【问题标题】:Discord Bot Responding to Phrase (Discord.py Rewrite)Discord Bot 响应短语(Discord.py 重写)
【发布时间】:2019-02-26 19:41:16
【问题描述】:

现在,我正在尝试为 Discord Bot 编写一个事件(使用 Discord.py Rewrite 包),该事件将在聊天中发送特定短语时发送图像。

根据我收到的错误消息,它似乎没有传递 Message 参数,因为我很可能在某处遗漏了一些东西。侦听器似乎正在按应有的方式工作(它会在有人在聊天中说话的那一刻触发)。

这是我收到的错误消息以供参考:

忽略消息 Traceback 中的异常(最近一次调用最后一次):

文件“C:\Program Files (x86)\Python36-32\lib\site->packages\discord\client.py”,第 221 行,在 _run_event await coro(*args, **kwargs) TypeError: dealwithit() missing 1 required >positional argument: 'message'

这里是sn-p的代码供参考

@bot.event
async def dealwithit(ctx,message):
    msg = message.content
    msg = msg.lower()
    msg = "".join(msg.split())
    if ctx.user.id != message.author.id:
        if msg == "dealwithit":
            dealwithit= discord.File('swag.jpg', filename='swag.jpg')
            await client.send_message(content=None,file=dealwithit)

bot.add_listener(dealwithit,'on_message')

任何关于我可能缺少的没有传递参数或设置不正确的帮助将不胜感激。

【问题讨论】:

  • 你可能想使用 bot.command 而不是 bot.event
  • 那行不通。给我一个错误:文件“C:\Program Files (x86)\Python36-32\lib\site-packages\discord\ext\commands\bot.py”,第 455 行,在 add_listener raise discord.ClientException('Listeners must be coroutines') discord.errors.ClientException: Listeners must be coroutines
  • 监听器和事件没有通过ctx。你需要去掉@bot.event,因为dealwithit不是一个事件名称。

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


【解决方案1】:

这是使用不和谐命令的重写

    bot = commands.Bot(command_prefix='!')
    @bot.command(pass_context=True)
    async def dealwithit(ctx):
        sendfile = open("swag.jpg", "rb")
        await bot.send_file(ctx.author.channel, sendfile)
        sendfile.close()

【讨论】:

    【解决方案2】:

    on_message 只有 message 参数,所以不带 ctx 试试。

    【讨论】:

      猜你喜欢
      • 2020-02-23
      • 2018-12-02
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 2021-12-26
      • 2021-04-15
      相关资源
      最近更新 更多