【问题标题】:discord.py make command cooldownsdiscord.py 使命令冷却
【发布时间】:2021-05-13 00:48:52
【问题描述】:

如何让命令有冷却时间

我有这个代码:

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

我希望该命令只能每 5 分钟使用一次

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    我认为这可行:

    @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)
    

    【讨论】:

      【解决方案2】:

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

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

      对于time,您可以设置任何时间,只要是秒,如果不是像 5 分钟这样的秒,则将分钟转换为秒 (5m x 60sec = 500sec)。

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

      • BucketType.default 面向全球。
      • BucketType.user 针对每个用户。
      • BucketType.server 针对每台服务器。
      • BucketType.channel 针对每个频道。

      你可以找到更多关于它Here

      对于更新后的代码:

      @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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-30
        • 2021-03-11
        • 1970-01-01
        • 2021-04-06
        • 1970-01-01
        • 2021-04-25
        • 1970-01-01
        • 2021-05-20
        相关资源
        最近更新 更多