I was wondering how I can set a role for a member, after he reacted to an emoji. I've tried several ways but it hasn't worked anything yet.
AttributeError: 'Guild' object has no attribute 'add_roles'
I always get this error, I tried to replace Guild with User, Payload or Member, but it doesn't find it anyway
I have two file in my 'cogs' folder:
• roles.py - Handles the message with reactions (This file works perfectly)
• reaction.py - 'Listen' to the reactions to the message
import discord
import asyncio
import emoji
from discord.ext import commands
from discord.utils import get
client = commands.Bot(command_prefix='/',preload=True)
class Reaction(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
guild_id = payload.guild_id
guild = self.client.get_guild(guild_id)
user_id = payload.user_id
user = self.client.get_user(user_id)
message_id = payload.message_id
channel = self.client.get_channel(payload.channel_id)
emoji = payload.emoji.name
if message_id == 809523588721934336 and emoji == "????" and user_id != 799612948213399572:
message = await channel.fetch_message(message_id)
await message.remove_reaction("????", user)
dev = get(guild.roles, id=799632281639321632)
await guild.add_roles(dev)
def setup(client):
client.add_cog(Reaction(client))