首先,您必须检查用户是否具有新角色。然后,您可以检查他们所担任的角色是您所寻找的角色之一:
@bot.event
async def on_member_update(before, after):
if len(before.roles) < len(after.roles):
new_role = next(role for role in after.roles if role not in before.roles)
if new_role.name in ('android', 'human'):
fmt = "{0.mention} your role request has been accepted! :confetti_ball: You've been granted the role '{1}'"
await bot.send_message(bot.get_channel('495285593711050754'), fmt.format(after, new_role.name))
elif new_role.name in ('moderator'):
fmt = "{0.mention} you are Now part of the CyberLife staff, we're so excited to have you here! :confetti_ball:"
await bot.send_message(bot.get_channel('495285593711050754'), fmt.format(after))