Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord bot adding reactions to a message discord.py (no custom emojis)

I've been trying to make a bot using discord.py add a reaction to a message using discord.py after reading this (which is not what I wanted because I am not using custom emojis) but it ends up giving this error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InvalidArgument: message argument must be a Message

I tried this code

@commands.command(pass_context=True)
async def emoji(ctx):
    msg = "working"
    await bot.say(msg)
    reactions = ['dart']
    for emoji in reactions: await bot.add_reaction(msg, emoji)

Any other related questions here on discord.py are just not helpful for this Any ideas on how to implement this

like image 559
Carlos Mediavilla Avatar asked Dec 28 '25 18:12

Carlos Mediavilla


2 Answers

Adding on to this as I came across this question wondering how to add reactions in 2022, in case someone else runs into this.

The method displayed in the answer above containing:

@commands.command(pass_context=True)
async def emoji(ctx):
    msg = await bot.say("working")
    reactions = ['dart']
    for emoji in reactions: 
        await bot.add_reaction(msg, emoji)

This will no longer work and you will get an error like:

AttributeError: 'Bot' object has no attribute 'add_reaction'

Instead, you'll want to do something like:

## EXAMPLE
@bot.command()
async def example(ctx):
    msg = await ctx.send("Hello")
    reaction = '👋'
    await msg.add_reaction(reaction)

For multiple reactions, I've also found that you need to do them separately:

## EXAMPLE
@bot.command()
async def example(ctx):
    msg = await ctx.send("Hello")
    reaction1 = '👋'
    reaction1 = '🙂'
    await msg.add_reaction(reaction1)
    await msg.add_reaction(reaction2)

And, for anyone wondering about custom emojis: (retrieve the emoji ID by typing \ then clicking the emoji, or you can go to save the file of the custom emoji and copy the default value it gives you.)

## EXAMPLE
@bot.command()
async def example(ctx):
    msg = await ctx.send("Hello")
    reaction1 = "<:yes:965728109200552036>"
    reaction1 = "<:no:965728137122050068>"
    await msg.add_reaction(reaction1)
    await msg.add_reaction(reaction2)
like image 82
clxrity Avatar answered Dec 31 '25 08:12

clxrity


The error message is telling you what the error is: "message argument must be a Message"

In the line

await bot.add_reaction(msg, emoji)

msg is a string, not a Message object. You need to capture the message you send and then add the reactions to that message:

@commands.command(pass_context=True)
async def emoji(ctx):
    msg = await bot.say("working")
    reactions = ['dart']
    for emoji in reactions: 
        await bot.add_reaction(msg, emoji)

Note that in later versions of discord.py, add_reaction has changed from bot.add_reaction(msg, emoji) to await msg.add_reaction(emoji).

like image 34
Patrick Haugh Avatar answered Dec 31 '25 09:12

Patrick Haugh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!