【问题标题】:How to make a Discord Bot repeat and simulate a user reply?如何让 Discord Bot 重复并模拟用户回复?
【发布时间】:2021-03-31 13:54:09
【问题描述】:

提前感谢任何阅读本文的人

我想让我的不和谐机器人遵循用户回复功能:

this is how I wanted it to be like

对于示例中没有使用真正的机器人表示歉意。运行 Opera 时无法打开或运行代码。

这是我目前编写的代码

    if "ngab" in message.content or "Ngab" in message.content or "NGAB" in message.content:
        content=message.content.lower()
        final=content.replace("ngab",":ng::ab:")
        if len(final)<=2000:
            await message.delete()        
            await message.channel.send(f'{message.author.mention}: {final}')
        else:
            await message.reply(f"too long :ng::ab: {message.author.mention}")

当我用“ngab”回复另一个用户时,机器人只会重复消息的内容,但我希望它像我发送的消息一样回复。

我不知道如何达到预期的效果,我只知道如何让机器人回复相应的消息。

感谢任何可以提供帮助的人,为我在这个问题中犯的任何错误道歉,这是第一次在这里提问。 :)

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    很简单,你必须检查消息是否有引用。

    if len(final)<=2000:
                ref = message.reference
                await message.delete()        
                await message.channel.send(f'{message.author.mention}: {final}', reference=reference)
            else:
                await message.reply(f"too long :ng::ab: {message.author.mention}")
    

    我们查找消息是否有任何引用(如果是回复),然后回复该消息。

    参考资料:

    【讨论】:

      猜你喜欢
      • 2021-07-04
      • 1970-01-01
      • 2023-04-10
      • 2021-02-07
      • 1970-01-01
      • 2022-10-21
      • 2021-07-30
      • 2021-10-31
      • 2018-11-21
      相关资源
      最近更新 更多