1
votes

I tried to make it so that the bot will congratulate anyone who is promoted from Member to Respected (it doesn't automatically promote it; admins/owner does). However, for the following code, every time I promote someone from Member to Respected, it wouldn't detect the promotion.

@client.event
async def on_member_update(before, after):
    if [i.id for i in before.roles].count(650019191092674569) == 1:
        if [i.id for i in after.roles].count('658164877172408320') == 1:
            channel = client.get_channel(649833392854007808)
            print(f"""Recognized that {after.name} has been promoted from Member to Respected""")
            await channel.send(f"""Congratulations {after.mention} for getting promoted to Respected!""")

I have also tried out this code, though the bot also didn't detect the promotion.

@client.event
async def on_member_update(before, after):
    if before.roles.count(650019191092674569) == 1:
        if after.roles.count('658164877172408320') == 1:
            channel = client.get_channel(649833392854007808)
            print(f"""Recognized that {after.name} has been promoted from Member to Respected""")
            await channel.send(f"""Congratulations {after.mention} for getting promoted to Respected!""")

Please help? Thank you!

2

2 Answers

1
votes

Here's some code I hope can help you on your quest to create some working solutions. This code will send a message whenever someone gets the respected role

@client.event
async def on_member_update(before, after):
    if len(before.roles) < len(after.roles):
        # The user has gained a new role, so lets find out which one
        newRole = next(role for role in after.roles if role not in before.roles)

        if newRole.name == "Respected":
            # This uses the name but you could always use newRole.id == Roleid here
            # Now, simply put the code you want to run whenever someone gets the "Respected" role here

Hope this helped!

0
votes

The Role ID is always an integer, in line 4 you have a string.

You can also omit the == 1, as you can only have 0/1 of the roles.

@client.event
async def on_member_update(before, after):
    if [i.id for i in before.roles].count(650019191092674569):
        if [i.id for i in after.roles].count(658164877172408320):
            channel = client.get_channel(649833392854007808)
            print(f"""Recognized that {after.name} has been promoted from Member to Respected""")
            await channel.send(f"""Congratulations {after.mention} for getting promoted to Respected!""")