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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-08-03 11:00:00 +0000
Seen: 10 times
Last updated: Sep 08 '21
How can data be added to a group and retrieved only by its members?
Which type in an assembly is not a member of a Namespace in C#?
Is it possible to automatically assign a role to a new member upon joining in Wix?
What is a one-line solution for setting the member m value to x in all objects within a list?
How can I resolve the "Type 'CMTime' has no member 'zero'" issue in Xcode version 16.2?