【问题标题】:All my @client.events work but not my @client.command, but if its just the command and the on_ready event, the @client.command works [duplicate]我所有的@client.events 都有效,但不是我的@client.command,但如果它只是命令和 on_ready 事件,@client.command 有效[重复]
【发布时间】:2020-05-11 05:49:19
【问题描述】:

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

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!')

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    如果你覆盖on_message,你需要在其中调用Bot.process_commands,这样命令仍然会被处理。

    请参阅Why does on_message make my commands stop working? section of the FAQ in the documentation

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 2015-05-11
      • 2016-01-31
      • 2022-02-25
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      相关资源
      最近更新 更多