error 10011 Unknown role with present defined role

Viewed 24

I'm trying to create a reactroles function for my server, I've gone through hundreds of stack overflow and reddit forums to find bits and pieces to make this work but nothing has fixed this last error.

The roles are present on my server and properly defined (as far as i know) in the code but still returns error 10011 Unknown Role

async def on_reaction_add(reaction, user):
    ChID = '1018712244843970610'
    ctx = await bot.get_context(reaction.message)
    #user = ctx.reaction.author
    Channel = bot.get_channel(1018712244843970610)
    if reaction.message.channel != Channel:
        await Channel.send("this is a test for ChID not....")
        return
    if reaction.emoji == "":
        await ctx.channel.purge(limit=1)
        this_member = ctx.message.author
        mem = str(this_member.display_name)
        await Channel.send(mem+" - this is a test for running....")
        print(this_member)
        this_guild = this_member.guild
        this_role = discord.utils.get(this_guild.roles, id=1018802229341327370)
        await this_member.add_roles(this_member, this_role)
        
    if reaction.emoji == "":
        await ctx.channel.purge(limit=1)
        this_member = ctx.message.author
        mem = str(this_member.display_name)
        await Channel.send(mem+" - this is a test for hammer....")
        this_guild = this_member.guild
        this_role = discord.utils.get(this_guild.roles, id=1018802151679602798)
        await this_member.add_roles(this_member, this_role)
        
    if reaction.emoji == "":
        await ctx.channel.purge(limit=1)
        this_member = ctx.message.author
        mem = str(this_member.display_name)
        await Channel.send(mem+" - this is a test for duck....")
        this_guild = this_member.guild
        this_role = discord.utils.get(this_guild.roles, id=1018802188555927572)
        await this_member.add_roles(this_member, this_role)
        
    if reaction.emoji == "❤️":
        await ctx.channel.purge(limit=1)
        this_member = ctx.message.author
        mem = str(this_member.display_name)
        await Channel.send(mem+" - this is a test for heart....❤️")
        this_guild = this_member.guild
        this_role = discord.utils.get(this_guild.roles, id=1018802188555927572)
        await this_member.add_roles(this_member, this_role)
    

I have tried replacing the ctx in ct.message.author with reaction.message.author but then throws the error 'reaction' has no attribute 'content'

I thought maybe the definition of this_member was the cause of it not being able to define the role but it doesnt seem to be the issue

1 Answers

I used this code, and it works:

@bot.event
async def on_raw_reaction_add(payload):

    Channel_id = 1018712244843970610
    Channel = bot.get_channel(Channel_id)
    data = {"":["running",1018802229341327370], "":["hammer",1018802229341327370], "":["duck",1018802229341327370], "❤":["heart",1018802188555927572]}

    if payload.channel_id != Channel_id:
        await Channel.send("this is a test for ChID not....")
        return

    if payload.emoji.name in data:
        this_guild = await bot.fetch_guild(payload.guild_id)

        all_roles = discord.utils.get(this_guild.roles, name="Bot")
        text, role_id = data[payload.emoji.name]
        await Channel.purge(limit=1)
        this_member = await this_guild.fetch_member(payload.user_id)
        mem = str(this_member.display_name)
        await Channel.send(mem+" - this is a test for {0}....{1}".format(text, payload.emoji))
        print(this_member)
        this_role = discord.utils.get(this_guild.roles, id=role_id)
        await this_member.add_roles(this_member, this_role)

Raw_reaction_add is for messages older than the start of the bot. If this does not work, check the Ids of the role.

Related