'Why does on_member_join() is not working in my discord.py bot? [duplicate]
I try to run this code below, but on_member_join is not working for me.
async def on_member_join(self, member):
guild = member.guild
if guild.system_channel is not None:
to_send = f'Welcome {member.mention} to {guild.name}!'
await guild.system_channel.send(to_send)
# self.logger.info(f'{member.mention} 加入了伺服器')
full code: https://github.com/Cutespirit-Team/CutespiritDiscordBot/blob/main/src/ctbot/ctbot.py#L66-L71
run python -m src/ctbot/
I have already turned this on.

when a user enter my server, it will show the default message. how can i fix it? thx
Solution 1:[1]
Make sure to subscribe to members intent.
class Bot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.members = True
super().__init__(intents=intents)
Solution 2:[2]
I used this but Im new to this stuff so idk its better or worse just know it works for me:
async def on_member_join(member):
channel = bot.get_channel(channel_id)
embed=discord.Embed(title='Welcome!', description=f"{member.mention} Just Joined")
await channel.send(embed=embed)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | uchur |
| Solution 2 | Alex Qnon |
