discord.py - 如何为斜杠命令的响应添加 react ?

标签 discord.py nextcord

当机器人响应我输入的斜杠命令时,我在尝试向机器人的响应中添加 react 时遇到问题

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

正如您所看到的,它应该添加对其自己的消息的 react 。 但我收到这个错误:

nextcord.errors.ApplicationInvokeError:命令引发异常:AttributeError:“PartialInteractionMessage”对象没有属性“add_reaction”

请告诉我如何向斜杠命令添加 react 。

最佳答案

说明

根据错误,ctx.send 返回 PartialInteractionMessage。来自 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.

代码

@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('🤖')

关于discord.py - 如何为斜杠命令的响应添加 react ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73110608/

相关文章:

python - Discord 机器人将嵌入消息发送到另一个 channel

运行代码时,Python Discord 机器人无法上线

python - 使用discord.py,有什么方法可以让我的discord 机器人在成员选项卡的 'playing' 部分显示自定义消息?

python - Nextcord 斜杠命令 | nextcord.errors.HTTPException : 400 Bad Request (error code: 50035): Invalid Form Body

python - Nextcord:无法访问服务器上的 ffmpeg

discord - 使用 interaction.response.defer() [Nextcord] 后无法响应交互

python-3.x - 如何使用 discord.py "temporary ban"某人?

python - 安装 discord.py 1.0 时遇到问题