首页 > 解决方案 > 我所有的@client.events 都有效,但我的@client.command 无效,但如果它只是命令和on_ready 事件,@client.command 有效

问题描述

这是我的代码。它仍处于早期开发阶段。另外,我对开发机器人还很陌生。

import discord
from discord.ext import commands

client = discord.Client()
bot_prefix: str = ">"
client = commands.Bot(command_prefix=bot_prefix)


@client.event
async def on_ready():
    print('Miska Rise')

这是我现在的一个活动:

@client.event
async def on_message(message):
    if message.author == client.user:
        return None

    if message.content.startswith('woof') or message.content.startswith('Woof'):
        await message.channel.send('Bork!')

这是命令:

@client.command()
async def ping(ctx):
    await ctx.send('Pong!')

标签: pythondiscorddiscord.py

解决方案


如果您覆盖on_message,则需要调用Bot.process_commands它,以便仍处理命令。

请参阅为什么on_message使我的命令停止工作?文档中的常见问题解答部分


推荐阅读