'React for user role doesn't work - discord.py
I'm just building a discord bot for my discord server with discord.py. I made a code, but it won't work. It creates the message and you can react. Even the first debug message comes: User reacted to message.
But it won't give me the role. This is my code:
async def reactMsg(ctx):
send_sub = await ctx.message.channel.send("React to this message to subscribe NPT.")
reactions = ['✅']
for i in reactions:
await send_sub.add_reaction(i)
@client.event
async def on_raw_reaction_add(payload):
#You forgot to await the bot.get_channel
channel = client.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
guild = client.get_guild(payload.guild_id)
#Put the following Line
member = guild.get_member(payload.user_id)
reaction = discord.utils.get(message.reactions, emoji=payload.emoji.name)
print("Debug: User reacted to message")
# only work if it is the client
if payload.user_id == client.user.id:
return
if payload.message_id == 943634886642765874 and reaction.emoji == '✅':
roles = discord.utils.get(guild.roles, name='TrackerSub')
await member.add_roles(roles)
await reaction.remove(payload.member)
print("Debug: Give role to user")
Any ideas what I made wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
