gpt4 book ai didi

python - 如何通过BucketType定义命令错误消息

转载 作者:行者123 更新时间:2023-12-03 07:56:14 24 4
gpt4 key购买 nike

我对一个命令使用max_concurrency两次,以限制每个公会最多调用3次,每个用户最大一次调用:

@commands.max_concurrency(3,per=commands.BucketType.guild,wait=False)
@commands.max_concurrency(1,per=commands.BucketType.user,wait=False)
async def start(self, ctx):
我的问题是如何使用BucketType参数创建单独的错误消息。
例如,我要问的是:
@start.error
async def on_command_error(self,ctx,error):

if isinstance(error, commands.MaxConcurrencyReached):

guild_error = "Too many playing"
user_error = "You're already playing"

await ctx.send("guild_error or user_error depending on BucketType?")

最佳答案

通过使用MaxConcurrencyReached.per属性,我们可以找到BucketType并采取相应的措施。
例如:

@start.error
async def on_command_error(self,ctx,error):

if isinstance(error, commands.MaxConcurrencyReached):

guild_error = "Too many playing"
user_error = "You're already playing"
# Because error.per returns a BucketType, we can check it against BucketType.user and BucketType.guild.
if error.per == commands.BucketType.user:
await ctx.send(user_error)
elif error.per == commands.BucketType.guild:
await ctx.send(guild_error)

关于python - 如何通过BucketType定义命令错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65101090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com