'How to assign roles on raw reaction?
I want to build a bot that assigns roles based on reactions. What am I doing wrong?
CODE:
@client.event
async def on_raw_reacion_add(payload, user):
message_id = payload.message_id
if message_id == 750076609519943811:
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, client.guilds)
if payload.emoji.name == 'Tigre':
role = discord.utils.get(guild.roles, name='+$100.000')
await user.add_roles(role)
EDIT:
The bot starts just fine and it just not responding to this raw reaction
EDIT 2
Still nothing :(
@client.event
async def on_raw_reaction_add(payload):
if payload.message_id == 750087466765123647:
bbc_emoji = '<:bbc:639345897922101248>'
if payload.emoji.name == bbc_emoji:
print ('working')
Solution 1:[1]
You spelt the event name wrongly, it's on_raw_reaction_add. The event takes only one single parameter, namely payload. The second argument should not be there. If you want to get who added the reaction you can use payload.member. The emoji name will be <:name:id> not "Tigre".
Solution 2:[2]
The error lies in if payload.emoji.name == bbc_emoji:. If you cut the variable from the if-statement your code is
if payload.emoji.name == '<:bbc:639345897922101248>':
However, the payload argument returns emoji.name and emoji.id seperately. You can check by running print(payload).
Therefore, your code should be:
@client.event
async def on_raw_reaction_add(payload):
print(payload)
if payload.message_id == 750087466765123647:
if payload.emoji.id == 639345897922101248:
print ('working')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Catalina Chircu |
| Solution 2 | timlwsk |
