Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py、bot.event有效,但bot.command无效_Python_Discord_Discord.py - Fatal编程技术网

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

Python Discord.py、bot.event有效,但bot.command无效,python,discord,discord.py,Python,Discord,Discord.py,所以,如果我实现了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 = co

所以,如果我实现了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可以完美地工作。
怎么了 因为您有一个关于消息的
事件。当您的bot中有
on\u message
事件时,您需要在
on\u message
事件代码的最后一行添加
wait bot.process\u命令(message)
。否则它将阻止命令工作。

现在可以工作了!非常感谢。你能解释一下为什么会这样吗?
等待bot.process\u命令(消息)
做什么?您应该检查。从那里我知道的不多。