繁体   English   中英

如何获取交互响应消息 object - discord.py

[英]How to get the interaction response message object - discord.py

最近,我一直在开发各种命令,它需要交互消息才能执行一些操作(例如在视图超时一段时间后删除它,这需要将消息作为属性分配给视图) .

但是,问题是我的代码总是将交互消息返回为 None; 我做了一些研究,发现 - 令我沮丧的是 - 交互响应不会返回它们的交互消息。 这是一个最小的可重现示例(请注意,我使用的是 cogs):

@app_commands.command()
async def command(self, interaction: discord.Interaction):
    message = await interaction.response.send_message('Hey!')
    print(message)

每当我运行此命令时,它都会打印None 但是,我希望它打印由交互响应发送的消息 object。 有没有其他方法可以做到这一点?

任何帮助将不胜感激。

找到方法了!

它是await interaction.original_response()

所以现在,如果我这样做:

@app_commands.command()
async def command(self, interaction: discord.Interaction):
    await interaction.response.send_message('Hey!')
    message = await interaction.original_response()
    print(message)

我收到了我想要的相应消息 object。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM