Discord python on role grant event

后端 未结 1 935
面向向阳花
面向向阳花 2020-12-20 06:35

So i\'ve been trying to get the bot to announce whenever a member gets a role granted, i know that this code may not make sense at all, but that\'s why i\'m asking: How coul

相关标签:
1条回答
  • 2020-12-20 06:59

    First you have to check that the user got a new role. Then you can check that the role they got is one of the ones you're looking for:

    @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))
    
    0 讨论(0)
提交回复
热议问题