discord.py使命令冷却



如何使命令具有冷却时间

我有这样的代码:

@commands.command
async def reward(self, ctx):
ctx.user.send("You claimed your reward")
Money.add(user.id, 50)

我想命令只能每5分钟使用一次

我想这样可以:

@commands.command
@commands.cooldown(1, 300, commands.BucketType.user)
async def reward(self, ctx):
ctx.user.send("You claimed your reward")
Money.add(user.id, 50)

你可以做@commands.cooldown({rate}, {time},commands.BucketType.{type})

rate是每个基础命令的使用次数(例如,如果您输入2,它将变成每个基础2个使用命令)

对于time,你可以把你想要的任何时间,只要它是秒,如果它不是秒像5分钟,将分钟转换为秒(5m x 60sec = 500sec)。

最后,commands.BucketType.{type}是基于每个服务器、每个通道、每个用户或全局的类型。它有四种类型:

  • BucketType.defaultfor global basis.
  • BucketType.user基于每个用户。
  • BucketType.server为每个服务器的基础。
  • BucketType.channel为每通道基础。

您可以在这里找到更多信息

更新后的代码:

@commands.command
@commands.cooldown(1, 300, commands.BucketType.user)
async def reward(self, ctx):
ctx.user.send("You claimed your reward")
Money.add(user.id, 50)

最新更新