How Do I Give Out A Role When I Click On A Reaction? It Doesn't Work For Me?
I'm trying to make sure that when you enter a command, a message is sent and a reaction is set, and those who click on the reaction get a role, but when you enter a command, nothin
Solution 1:
You can indeed make some kind of "event" in a command. However your code contains some errors that we have to take care of first.
First: If you want to add a reaction to a message you always have to prefix it with await
, otherwise it won't work and you'll get the following error:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Second:member
and emoji
don't make any sense here, because you didn't include an event
. You also cannot use payload
.
Have a look at the following code:
@client.command(pass_context=True)@commands.has_permissions(administrator=True)asyncdefmp(ctx):
emb = discord.Embed(title=f'Праздник вазилина', description='Нажми на реакцию что бы получить роль',
colour=discord.Color.purple())
message = await ctx.send(embed=emb) # Send embedawait message.add_reaction('✅') # Add reaction
roles = discord.utils.get(message.guild.roles, id=RoleID) # Replace it with the role ID
check = lambda reaction, user: client.user != user # Excludes the bot reactionwhileTrue:
reaction, user = await client.wait_for('reaction_add', check=check) # Wait for reactionifstr(reaction.emoji) == "✅":
await user.add_roles(roles) # Add roleprint('[SUCCESS] Пользователь {0.display_name} получил новую роль {1.name}'.format(user, roles)) # Printawait user.send('TEST') # Send message to member
To allow multiple reactions we built in a while True
"loop".
Post a Comment for "How Do I Give Out A Role When I Click On A Reaction? It Doesn't Work For Me?"