为了账号安全,请及时绑定邮箱和手机立即绑定

Discord.py bot.command 在使用 on_message 后停止工作

Discord.py bot.command 在使用 on_message 后停止工作

白猪掌柜的 2023-10-26 15:50:19
我有一个包含 bot.command 和 bot.event 的脚本,但由于某种原因只有 bot.command 正在工作bot.command 和 bot.event 单独工作,但由于某种原因不能一起工作这是代码:# bot.pyimport discordfrom discord.ext import commandsfrom discord.utils import getTOKEN = ('token')bot = commands.Bot(command_prefix=',')@bot.eventasync def on_ready():    print(f'{bot.user} has connected to Discord!')@bot.eventasync def on_message(message):    if foo:        await message.channel.send("foo")@bot.command(pass_context=True)async def foo(ctx, args):    foo = bot.get_user(args)    await ctx.send(foo)bot.run(TOKEN)谢谢
查看完整描述

1 回答

?
慕后森

TA贡献1802条经验 获得超5个赞

您需要on_message处理机器人的命令:

await bot.process_commands(message)

而且你也不需要pass_context=True再使用了,现在就已经过去了。


查看完整回答
反对 回复 2023-10-26
  • 1 回答
  • 0 关注
  • 60 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信