Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.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 为什么on_消息使命令停止工作?_Python_Python 3.x_Discord_Discord.py_Discord.py Rewrite - Fatal编程技术网

Python 为什么on_消息使命令停止工作?

Python 为什么on_消息使命令停止工作?,python,python-3.x,discord,discord.py,discord.py-rewrite,Python,Python 3.x,Discord,Discord.py,Discord.py Rewrite,基本上,一切都正常工作并启动,但由于某些原因,我无法调用任何命令。我已经四处寻找了一个小时,看看例子/看视频,但我一辈子都搞不清楚到底是怎么回事。代码如下: import discord import asyncio from discord.ext import commands bot = commands.Bot(command_prefix = '-') @bot.event async def on_ready(): print('Logged in as') pri

基本上,一切都正常工作并启动,但由于某些原因,我无法调用任何命令。我已经四处寻找了一个小时,看看例子/看视频,但我一辈子都搞不清楚到底是怎么回事。代码如下:

import discord
import asyncio
from discord.ext import commands

bot = commands.Bot(command_prefix = '-')
@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')

@bot.event
async def on_message(message):
    if message.content.startswith('-debug'):
        await message.channel.send('d')

@bot.command(pass_context=True)
async def ping(ctx):
    await ctx.channel.send('Pong!')

@bot.command(pass_context=True)
async def add(ctx, *, arg):
    await ctx.send(arg)
我在on_消息中的调试输出实际上起作用并响应,整个bot运行时没有任何异常,但它只是不调用命令。

覆盖\u消息上提供的默认值
将禁止运行任何额外的命令。要解决此问题,请在消息的
末尾添加
bot.process\u命令(消息)
行。例如:

@bot.event
async def on_message(message):
    # do some extra stuff here

    await bot.process_commands(message)
_message
上的默认
包含对此协同程序的调用,但当您用自己的
on_message
覆盖它时,您需要自己调用它