简体   繁体   English

discord.py bot 命令冷却适用于所有人进行工作命令

[英]discord.py bot command cooldown applies to everyone for work command

i have a work command for my discord.py bot with a hour cooldown.我有一个冷却时间为一小时的 discord.py 机器人的工作命令。 So if i do >work and then someone else does >work , it tells them they must wait for an hour.因此,如果我做>work然后其他人做>work ,它会告诉他们他们必须等待一个小时。 How can i get the cooldown to only apply to one user when the do >work ?当 do >work时,我怎样才能让冷却时间仅适用于一个用户? Thx谢谢

this is the code that i have for the cooldown and command,这是我用于冷却和命令的代码,

class Economy(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.last_work_time = None

    def on_work_waiting():
      time.sleep(3600)
      last_work_time = None

    def on_work_typed():
      if last_work_time is None:
        last_work_time = datetime.datetime.now()
        threading.Thread(target: on_work_waiting).start()
  
    else:
        time_left = datetime.datetime.now() - last_work_time
        minutes_left, _ = divmod(time_left.total_seconds(), 60)

        await ctx.send(f'{ctx.author.mention}, Wait {minutes_left} minutes until you can work again!')


    @commands.cooldown(1, 3600, commands.BucketType.user)

    @commands.command()
    async def work(self, ctx):
      database.load()
      randomjobtitle = ["Construction Worker", "Teacher", "Twitch Streamer", "911 Dispatcher", "Librarian", "Cookie Giver", "Fast Food Worker"]
      job = random.choice(randomjobtitle)
      author = ctx.author
      money = random.randint(10,50)
      balance = database[str(ctx.message.author.id)]
      total = database[str(ctx.message.author.id)] = balance + money
      embed=discord.Embed(title=f"{ctx.author.name} decided to work!", description="You're going to work!", color=0x00FFFF)
      embed.add_field(name="Amount Earned", value=f"**{money}** Ulti Coins", inline=True)
      embed.add_field(name="Job Title (random)", value=f"**{job}**", inline=True)
      embed.add_field(name="Balance Before Work", value=f"**{total}** Ulti Coins", inline=True)
      embed.set_thumbnail(url=author.avatar_url)
      embed.set_footer(text="Your total amount is saved across all servers that I'm in! >balance to see your balance")
      await ctx.send(embed=embed)
      try:
        balance = database[str(ctx.message.author.id)]
      except:
        balance = 0
      database[str(ctx.message.author.id)] = balance + money

Your command cooldown, @commands.cooldown(1, 3600, commands.BucketType.user) , should already be working this way.您的命令冷却时间@commands.cooldown(1, 3600, commands.BucketType.user)应该已经以这种方式工作。 You are using the user BucketType which applies a cooldown on a per-user basis .您正在使用user BucketType ,它基于每个用户应用冷却时间 Based on how your bot is being used, the person who still has that cooldown could be doing the command in another server.根据您的机器人的使用方式,仍然有冷却时间的人可能正在另一台服务器上执行命令。 In that case, you could use the member BucketType .在这种情况下,您可以使用member BucketType

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM