discord.py中的代码无法识别两个同时发生的事件



我正在为我朋友的不和制作一个机器人,它是一个计算器,它还必须用一些笑话回答一些关键词,问题是,它通常像计算器一样工作,但当我添加用笑话回答关键词的事件时,计算器停止工作,只发送笑话。计算器看起来像这样:

client = commands.Bot(command_prefix='&', help_command=None)

@client.event
async def on_ready():
print('on')
def raizes(a: float, b: float, c: float):
return (-b + math.sqrt((b ** 2) - 4 * a * c)) / 2 * a, (-b - math.sqrt((b ** 2) - 4 * a * c)) / 2 * a

@client.command()
async def matraizes(ctx, a: float, b: float, c: float):
res = raizes(a, b, c)
await ctx.send(res)

然后我一添加此事件,它就停止工作:

@client.event  
async def on_message(message):
if message.author == client.user:
return
if message.content.lower().startswith('test'):
await message.channel.send('ok')

在添加on message事件之前,discord.py已经有了默认的on message事件-用于处理命令。现在您创建了自己的事件,它会覆盖默认的消息事件,但这可以很容易地解决,因为您所要做的就是再次处理命令。

@client.event  
async def on_message(message):
if message.author == client.user:
return
if message.content.lower().startswith('test'):
await message.channel.send('ok')

await client.process_commands(message)

最新更新