python - Python Discord bot 不会运行命令,但会运行 on_message(),这是为什么呢?
问题描述
import discord
from discord.ext import commands
import random
print("Starting bot...")
TOKEN = (the token)
client = commands.Bot(command_prefix='?')
# answers with the ms latency
@client.command(name='ping', pass_context = True)
async def ping(ctx):
await ctx.send(f'Pong! {round(client.latency * 1000)}ms ')
client.run(TOKEN)
它运行任何 on_message 命令,但不运行其他任何命令。我查看了 SO 中的许多教程网站和页面,但似乎都没有。
解决方案
查看 TeilaRei 的上一篇文章,您需要在 on_message() 中添加一行。
推荐阅读
- asp.net-core - 在 RHEL 7 中运行 ASP.NET Core 的问题
- python - Pandas 列中的多个局部最大值超过阈值
- react-admin - 操作创建按钮路径
- visual-studio-2017-build-tools - 以正确的编码生成 .resx 资源文件
- docker - Docker 构建时间戳
- google-sheets - 如何使用 IMPORTRANGE 从底部进行 VLOOKUP
- sql - R相当于SQL中的LIKE子句[使用查找表]?
- python - 有没有更好的方法从python中的输入文件生成rest api端点?
- python - 在 DataFrame 嵌套数组上应用条件
- python - 从相关目录迭代导入 Python 脚本