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
覆盖它时,您需要自己调用它