Discord.py - 如何让人们等待一段时间再次使用命令?

时间:2021-04-22 08:07:49

标签: python discord.py

我想做一个命令“乞求”,但我不希望人们总是使用它并赚钱,那么是否可以让人们等待一段时间再次使用该命令?

1 个答案:

答案 0 :(得分:0)

discord.ext.commands 有一个装饰器函数 cooldown。需要 3 个参数:

per => 在使用多少次之后

rate => 等待的秒数

类型 => 冷却类型。可以是公会、用户、频道、角色

在齿轮中

@commands.command(name="ping")
@commands.cooldown(per=1, rate=3.0, type=commands.BucketType.user)
async def ping(self, ctx):
  await ctx.send("Pong!")

不在齿轮中

@bot.command(name="ping")
@commands.cooldown(per=1, rate=3.0, type=commands.BucketType.user)
async def ping(ctx):
  await ctx.send("Pong!")