Arpith Anto
Arpith Anto

Reputation: 55

How do you add a reaction to the response of a slash command?

I'm facing problems trying to add a reaction to the bot's response when it responds to a slash command I entered.

@bot.slash_command(name='test', description="Test.")
async def test(ctx):
  msg = await ctx.send("Hello.")
  await msg.add_reaction('🤖')

As you can see it's supposed to add a reaction to it's own message. But I get this error:

nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'PartialInteractionMessage' object has no attribute 'add_reaction'

Please tell me how do I add a reaction to a slash command.

Upvotes: 2

Views: 1006

Answers (1)

TheFungusAmongUs
TheFungusAmongUs

Reputation: 1516

Explanation

As per the error, ctx.send is returning a PartialInteractionMessage. From the docs:

This does not support most attributes and methods of nextcord.Message. The fetch() method can be used to retrieve the full InteractionMessage object.

Code

@bot.slash_command(name='test', description="Test.")
async def test(ctx):
  msg = await ctx.send("Hello.")
  full_msg = await msg.fetch()
  await full_msg.add_reaction('🤖')

Upvotes: 3

Related Questions