Ethitlan
Ethitlan

Reputation: 37

How can I add a reaction to a command sent by a user? [Discord.py]

So I'm trying to make it so that when a command is executed with no errors it will react to the command message with :white_check_mark: and if there's an error it will react with :x:. I've tried to do it with the load command and this is what I've got:

@commands.check(is_owner)
async def load(ctx, extension):
    try:
        client.load_extension(f"cogs.{extension}")
        print(f"The {extension} Cog has been loaded onto main file.")
        await ctx.add_reaction(":white_check_mark:")

    except:
        await ctx.add_reaction(":x:")

It doesn't work. Error command is:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'add_reaction'

How can I make it work?

Upvotes: 1

Views: 150

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

As the error said, Context doesn't have the add_reaction method. You're supposed to add the reaction to a Message instance, you can do that with:

await ctx.message.add_reaction("✅")

Also the reaction must be a unicode (if it's a default one), to get it simply \:emoji: in discord send and copy the resulting message.

Upvotes: 3

Related Questions