0

I want to do role logging in discord.py, example:

@bot.event
async def on_member_update(before, after)
 await channel.send(after.role)

so it will send the after role(the new role), but after doesn't have after.role that will return the new role so how do i get the new role name and id?

CrePz
  • 1
  • 1

1 Answers1

1

Since after.roles returns a list and before.roles, you can check what changed using:

changed_role_set = set(before.roles) ^ set(after.roles)
if len(changed_role_set) > 0
    changed_role = next(iter(changed_role_set))
    #and then answer
    await channel.send(f"The role {changed_role.name} got either removed or added to the user {after.name}")

References

LoahL
  • 2,404
  • 1
  • 9
  • 24