首页 > 解决方案 > 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 中的许多教程网站和页面,但似乎都没有。

标签: pythonpython-3.xdiscord

解决方案


查看 TeilaRei 的上一篇文章,您需要在 on_message() 中添加一行。


推荐阅读