Skip to content
Advertisement

discord.py the bot doesn’t give the role provided upon member join

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 with async 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 do member.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) to member.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)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement