【问题标题】:Allow Discord Rewrite bot to respond to other bots允许 Discord Rewrite 机器人响应其他机器人
【发布时间】:2019-08-14 13:36:38
【问题描述】:

我有一个 Discord 机器人和一个用于 Discord 频道的 webhook 设置,以每小时在 dot 上发送一个命令。然而,默认情况下,Discord Rewrite 似乎忽略了从其他机器人发送的命令。我该如何禁用它?

我需要在 per-command 函数或 on_message 函数上修改某些内容吗?

当前消息

@bot.event
async def on_message(message):
    await bot.process_commands(message)

编辑:找到解决方案

@bot.event
async def on_message(message):
    ctx = await bot.get_context(message)
    await bot.invoke(ctx)

【问题讨论】:

  • 我建议您发布您的解决方案作为答案,而不是编辑您的原始问题。这是在 stackoverflow 上执行此操作的常用方法。 :)
  • 不建议回复其他bot,如果回复了,就不能在top.gg中应用你的bot。
  • 默认情况下,您的机器人会响应其他机器人的消息。我不确定命令,但它确实响应消息编辑:你到底想要什么?其他机器人响应您的机器人?或您的机器人来响应其他机器人?

标签: python discord discord.py-rewrite


【解决方案1】:

尝试为它添加一个检查,例如:

on_message

if message.author.bot == True:
    #Do something

命令

if ctx.author.bot == True:
    #Do something

【讨论】:

  • 您应该使用is 而不是==。在这种情况下,== True 可以省略,因为User.bot 的值始终为 True 或 False
猜你喜欢
  • 2021-11-10
  • 2021-05-25
  • 2021-03-24
  • 2023-02-10
  • 2021-04-09
  • 2019-11-09
  • 2020-12-27
  • 2021-03-11
  • 2021-07-22
相关资源
最近更新 更多