You can assign a role when an emoji is reacted to by using the on_raw_reaction_add
event. Here's an example code:
@client.event
async def on_raw_reaction_add(payload):
if payload.message_id == MESSAGE_ID: # Replace MESSAGE_ID with the ID of the message you want to monitor
if str(payload.emoji) == '๐': # Replace ๐ with the emoji you want to monitor
guild = client.get_guild(payload.guild_id)
member = guild.get_member(payload.user_id)
role = guild.get_role(ROLE_ID) # Replace ROLE_ID with the ID of the role you want to assign
await member.add_roles(role)
This code listens for the on_raw_reaction_add
event and checks if the message ID and the emoji match the ones you are monitoring. If they do, it gets the guild, member, and role objects and assigns the role to the member.
Note: You'll need to enable gateway intents and have the members
intent enabled to get the guild.get_member
method to work.
Asked: 2021-08-03 11:00:00 +0000
Seen: 10 times
Last updated: Sep 08 '21