from discord.ext import commands
# this decorator is saying 1 command execution per user per day (time counted in seconds)
@commands.cooldown(1, 86400, commands.BucketType.user)
@bot.command()
async def daily(ctx):
# do something
@daily.error
async def daily_err(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(error) # tell the user when they can next use the command
else:
print(error)
您可以使用
commands.cooldown
装饰器设置命令的冷却时间它需要三个参数:
下面是一个允许每24小时执行一次的命令示例:
错误装饰器只取决于首选项-如果愿意,可以使用
on_command_error
创建一个错误处理程序参考文献:
相关问题 更多 >
编程相关推荐