Search code examples
pythondiscordbots

Discord.PY, reaction role error occuring?


Alright I am trying to create a command where the user does (prefix)requestrole discordid roleid. It then sends a request embed to a channel where certain roles can view that channel and they can click on either the checkmark reaction or the 'x' reaction to accept or deny the role request.

    @commands.command()
    async def requestrole(self, ctx, discordid, roleid):
        discordid = int(discordid)
        roleid = int(roleid)
        userid = ctx.author.id
        channel = self.bot.get_channel(FILLWITHCHANNELID)
        guild = ctx.guild
        user = ctx.author
        role = get(guild.roles, id=roleid)
        embed = discord.Embed(title="Role Request", description=f"{user} requested {role} for {userid}", color=0x00ff00)
        await channel.send(embed=embed)
        message = await embed.send(embed=embed)
        await message.add_reaction("✅")
        await message.add_reaction("❌")
        @self.bot.event
        async def on_reaction_add(reaction, user):
            if reaction.emoji == "✅":
                user = reaction.message.author
                guild = reaction.message.guild
                role = get(guild.roles, id=roleid)
                await user.add_roles(role)
                await channel.send(f"{user} has been given {role}")
            elif reaction.emoji == "❌":
                await reaction.message.send("Role request denied")

This is the error I am now receiving

Ignoring exception in command requestrole: Traceback (most recent call last): File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "C:\Users\name\Documents\GitHub\PRP-Bot\cogs\role_cog.py", line 31, in requestrole message = await embed.send(embed=embed) AttributeError: 'Embed' object has no attribute 'send'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 94, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Embed' object has no attribute 'send'

My question particularly is what is causing the error, and how do I properly code it so a person can basically click on the reaction checkmark to add the role, or click the x to remove the role.


Solution

  • you are trying to send a message to an Embed. That's not how Embeds work. you can send a message to a channel but not to a Embed. Just remove the line message = await embed.send(embed=embed) and you should be fine