【问题标题】:Check if message reply is a reply type message discord.py检查消息回复是否为回复类型消息 discord.py
【发布时间】:2021-07-01 12:08:59
【问题描述】:

我有以下基本的 python discord bot 代码:

@bot.command()
async def replyTest(ctx):
    await ctx.send('Reply to this message')
    def check(m):
        return m
    msg = await bot.wait_for("message", check=check)
    print(msg)

只有当m是回复类型的消息时,有没有办法返回m

【问题讨论】:

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


    【解决方案1】:

    您可以简单地检查消息是否有引用。

    def check(m):
        if m.reference is not None and not m.is_system :
             return True
        return False
    

    另外,如果您想检查引用是否指向消息

    def check(m):
       if m.reference is not None:
            if m.reference.message_id = some_msg.id
                return True
       return False
    

    参考资料:

    【讨论】:

    • 请注意,这将包括一些其他类型的消息,例如 pin 添加。
    • 通过检查修复它。感谢提及
    猜你喜欢
    • 2022-01-24
    • 2021-03-25
    • 2021-07-12
    • 2023-03-22
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 2021-03-17
    • 2023-03-21
    相关资源
    最近更新 更多