'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
Solution 1:[1]
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)
.
Solution 2:[2]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | TheKingElessar |
Solution 2 | clxrity |