I tried to set up this bot event where it would give a role to the member that joins. For some reason, it doesn’t give the role, but it doesn’t give any error output either.
@client.event def on_member_join(member): role = discord.utils.get(member.server.roles, id="868708006504833034") await client.add_roles(member, role)
Advertisement
Answer
@client.event def on_member_join(member): role = discord.utils.get(member.server.roles, id="868708006504833034") await client.add_roles(member, role)
There are a few issues with your code
- in line 2, the function is not async, discord.py events need to be async so replace
def
withasync def
- in line 3, ids are always ints, so you would make it an int, but you shouldn’t even use
discord.utils.get
since you can just domember.guild.get_role(id)
. Note: id has to be int - in line 4, client.add_roles is outdated, it was replaced by member.add_roles. So you would have to change
client.add_roles(member, role)
tomember.add_roles(role)
So the full updated code would be
@client.event async def on_member_join(member): role = member.guild.get_role(868708006504833034) await member.add_roles(role)