How to write a Discord Role Reaction Bot in Python w/ Discord.py
Why Stack Overflow recommends it
Stack Overflow users cite it as the tutorial they followed when their reaction-role bots failed to assign roles, and they post their adapted code as the question.
Recommended by 1 people across 1 different months, 2020 to 2022.
What it is
A 2019 tutorial by the YouTuber Anson that builds a Discord bot in Python with the discord.py library. The bot assigns server roles when members react to a message with certain emojis, using the on_raw_reaction_add event. The video is unedited, runs about 17 minutes, and links to the final code.
What people said
Recommends SKAI · 2020-09 · Stack Overflow · on “The discord bot wont assign a role”
I am following Anson the Developers tutorial, ( here's a link [this video] ) and I coded exactly as he did, I got no errors, except a warning Parameter 'payload' value is not used and I have made sure that: The bot has proper permissions to assign roles The bot is online The emojis and the roles have the same names heres the code for reference: import discord client = discord.Client() @client.event async def on_message(message): if message.author == client.user: return @client.event async def on_raw_reaction_add(payload): message_id = payload.message_id if message_id == '756794977148993597': guild_id = payload.guild_id guild = discord.utils.find(lambda g: g.id == guild_id, client.guilds) role = d
Cites Dylan Otis · 2021-01 · Stack Overflow · on “Discord.py bot, assign role when a user adds reaction”
I'm making a bot that i saw from this [this video] Here's the code I wrote @client.event async def on_raw_reaction_add(payload): message_id = payload.message_id if message_id == [message id]: guild_id = payload.guild_id guild = discord.utils.find(lambda g :g.id == guild_id, client.guilds) role = discord.utils.get(guild.roles, name=payload.emoji.name) if role is not None: member_user = discord.utils.find(lambda m : m.id == payload.member.id, guild.members) if member_user is not None: await member_user.add_roles(role) print("Done") else: print("Member not Found") print(member_user) else: print("Role not Found") But every time I react, the console gives me Member not Found and a None for the user ID
Cites user16777176 · 2022-01 · Stack Overflow · on “Reaction Role with nextcord”
On my Nextcord bot, I want to add a reaction role system. I've tried this code: @commands.Cog.listener() async def on_raw_reaction_add(self, payload): message_id = payload.message_id if message_id == 930812411097796618: guild_id = payload.guild_id guild = nextcord.utils.find(lambda g: g.id == guild_id, self.bot.guilds) if payload.emoji.name == "tada": role = nextcord.utils.get(guild.roles, id=896417683153752104) elif payload.emoji.name == "nut_and_bolt": role = nextcord.utils.get(guild.roles, id=896417735473528832) elif payload.emoji.name == "microphone": role = nextcord.utils.get(guild.roles, id=896417789458403368) elif payload.emoji.name == "part_alternation_mark": role = nextcord.utils.ge