Discord.py、bot.event 有效,但 bot.command 无效

因此,如果我实现了 bot.event,bot.command 就不起作用,但如果我评论或删除 bot.event,bot.command 就可以正常工作。


在这里,bot.command 不起作用,但 bot.event 起作用:


# bot.py

import os

from discord.ext import commands

from dotenv import load_dotenv


load_dotenv()

TOKEN = os.getenv('DISCORD_TOKEN')


bot = commands.Bot(command_prefix='dedmu ')



@bot.event

async def on_ready():

    print(f'{bot.user.name} has connected to Discord!')



@bot.event

async def on_message(message):

    if message.author == bot.user:

        return


    if message.content.lower() == 'testt':

        await message.channel.send('it works')



@bot.command(name='test')

async def test(ctx, arg):

    await ctx.send(arg)



bot.run(TOKEN)

如果我用 bot.event 注释这两个函数,则 bot.command 可以完美工作。它出什么问题了?:<


ibeautiful
浏览 49回答 1
1回答

BIG阳

因为你有一个on_message活动。当您的机器人中有on_message事件时,您需要await bot.process_commands(message)在事件代码的最后一行添加on_message。否则它将阻止命令工作。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python