我有这段代码:
from discord.ext import commands
@bot.command()
@commands.max_concurrency(1,per=commands.BucketType.default,wait=False)
async def function(ctx,arg1,arg2,arg3):
max_concurrency()
可以工作,但是当满足最大并发性时,我希望它向作者发送一条消息,指出该机器人很忙,我已经尝试了MaxConcurrencyReached
异常句柄,但是它根本不起作用,有人知道如何使用此命令吗?
答案 0 :(得分:3)
我知道了。
定义函数后,我要设置最大并发限制:
from discord.ext import commands
@bot.command()
@commands.max_concurrency(1,per=commands.BucketType.default,wait=False)
async def function(ctx,arg1,arg2,arg3):
然后,您必须使用on_command_error()
和isinstance()
处理它。例如:
@bot.event
async def on_command_error(ctx,error):
await ctx.message.delete()
if isinstance(error, commands.MaxConcurrencyReached):
await ctx.author.send('Bot is busy! Please retry in a minute')
return