获取你回复的消息的消息对象(Discord.py)

时间:2021-04-18 01:36:50

标签: python python-3.x discord discord.py

如何获取我回复的消息的消息对象?例如。有人说:“你好,你好吗!”。我回复了调用 .good 命令的消息,它会打印消息(你好,你好吗!)的消息对象。我已经查看了 discord.py 文档,但没有看到提及此类内容的内容。

1 个答案:

答案 0 :(得分:2)

您可以使用 discord.Message.reference 属性。在你的问题中,你会做这样的事情:

@client.command()
async def good(ctx):
    # If this message has a reference (meaning it's a reply)
    if ctx.message.reference:
        original = await ctx.fetch_message(id=ctx.message.reference.message_id)
        text = original.content
        print(f"Author said {text}")

这是文档的链接:https://discordpy.readthedocs.io/en/stable/api.html#discord.Message.reference