python - 我做了一个自动响应特定消息的命令。该命令有效,但它使我所有其他命令都不起作用(discord.py 重写)
问题描述
这是我在打招呼时用于命令响应的代码。这将起作用,但是如果我在它们都不起作用之后尝试使用命令,并且如果我将它从我的代码中取出,那么它会再次起作用。使用命令时没有错误代码。我真的不知道如何解决这个问题,有人知道为什么会这样吗?如果是这样,我该如何解决?
@client.event
async def on_message(message):
channel = client.get_channel(CHANNEL)
hello = "hello"
if message.content.count(hello) > 0:
message = "Whats up!"
await channel.send(message)
解决方案
使用on_message
事件时,您需要process_commands()
允许您的命令工作:
@client.event
async def on_message(message):
await client.process_commands(message)
# checking against lower case string will be more consistent with finding more "hello"s
if message.content.lower().count("hello") > 0:
await message.channel.send("What's up!")
参考:
Bot.process_commands()
- “如果你选择覆盖on_message()
事件,那么你也应该调用这个协程。”
推荐阅读
- c# - 将 Linq 转换为 Sql 表达式到使用连接到函数表的表达式树
- openedge - 如何迭代存储在数据库中的记录?
- javascript - web3.js 回调中的异步/等待顺序问题
- spring-boot - 如何在 Spring Boot 应用程序中通过 application.properties 禁用 WARN 消息并仅启用日志中的 INFO 消息?
- javascript - Cordova cammands 无法正确执行,而是永远挂起
- laravel - 在刀片组件中定义 vue 应用
- java - 为什么 Spring Security 禁止特定资源而不考虑角色?
- node.js - Passport.js 中的 Google 策略是否随着 Google+ 的结束而弃用
- python-3.x - Pytest - 测试用例执行顺序
- django - 如何从另一个场景中的一个步骤执行一个场景?