tec*_*ics 3 python discord discord.py
@bot.event所以我有一个同时使用和 的脚本@bot.command()。问题是,当我等待时,@bot.event它@bot.command()不会运行。
这是我的代码:
@bot.event
async def on_ready():
print("Bot Is Ready And Online!")
async def react(message):
if message.content == "Meeting":
await message.add_reaction("")
@bot.command()
async def info(ctx):
await ctx.send("Hello, thanks for testing out our bot. ~ techNOlogics")
@bot.command(pass_context=True)
async def meet(ctx,time):
if ctx.message.author.name == "techNOlogics":
await ctx.channel.purge(limit=1)
await ctx.send("**Meeting at " + time + " today!** React if you read.")
@bot.event ##THIS ONE HOLDS UP THE WHOLE SCRIPT
async def on_message(message):
await react(message)
Run Code Online (Sandbox Code Playgroud)
当混合使用事件on_message和命令时,您需要添加await bot.process_commands(message),如下所示:
@bot.event
async def on_message(message):
await bot.process_commands(message)
# rest of code
Run Code Online (Sandbox Code Playgroud)
正如文档中所说:
该函数处理已注册到机器人和其他组的命令。如果没有这个协程,则不会触发任何命令。
如果您选择覆盖 on_message() 事件,那么您也应该调用此协程。
参考:
| 归档时间: |
|
| 查看次数: |
15355 次 |
| 最近记录: |