【发布时间】:2017-09-29 20:34:33
【问题描述】:
我的目标是让我的机器人始终监听 discord.py 中的特定消息。在示例中,它应该监听的消息是 $greet,它应该通过在 Text To Speech 中大声朗读“Say hello”来响应它。
这很好用,但是它会禁用我设置的常规命令,例如 !play 和 !help。有没有办法绕过这个限制?
示例代码:
@my_bot.event
async def on_message(message, timeout=10,):
if message.content.startswith('$greet'):
await my_bot.send_message(message.channel, 'Say hello', tts=True)
msg = await my_bot.wait_for_message(author=message.author, content='hello')
await my_bot.send_message(message.channel, 'Hello.')
预期输出:
User: !play
Bot: Now playing...
User: $greet
Bot: Say hello
实际输出:
User: !play
User: $greet
Bot: Say hello
【问题讨论】:
-
您正在做的是覆盖处理命令运行的机器人中的默认 on_message 事件。由于您确实希望在此事件中出现特殊行为,这是正确的,但您需要调用处理随后运行的命令的方法。你也许可以在模块源中找到这个(搜索 on_message),我回家后会用它发布答案
-
非常欣赏这个 Blimmo,会赞成,因为这似乎确实是问题,但我不经常使用 Stack Overflow,所以我不知道如何。我会自己搜索并期待回音。
标签: python python-3.x discord