【发布时间】: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