'How to remotely set another command on cooldown when i do another command || Discord py

Is it possible so when i do a command, some other commands also get the cooldown? if it is possible, how to do it?

(like when i do !command1 i cant do !command2 until the cooldown of command1 done)

example of what thing i want to do:

@bot.command()
@commands.cooldown(1, 10, commands.BucketType.user)
async def command1(ctx):
  @command2.set_cooldown(ctx)

@bot.command()
@commands.cooldown(1, 10, commands.BucketType.user)
async def command2(ctx):
  @command1.set_cooldown(ctx)


Solution 1:[1]

To set a cooldown after the command is defined you have to mess a bit with the internal attributes, here's an example how to add and remove a cooldown after command creation (it depends from version to version, this example works on discord.py 1.7.3)

@bot.command()
async def command_to_add_cooldown(ctx):
   ...


@bot.command()
async def add_cooldown(ctx):
    rate, per, bucket_type = 1, 60.0, commands.BucketType.user  # cooldown settings
    cooldown_mapping = commands.CooldownMapping.from_cooldown(rate, per, bucket_type)
    command_to_add_cooldown._buckets = cooldown_mapping
    await ctx.send("Added cooldown")


@bot.command()
async def remove_cooldown(ctx):
    cooldown_mapping = commands.CooldownMapping(None)
    command_to_add_cooldown._buckets = cooldown_mapping
    await ctx.send("Removed cooldown")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Łukasz Kwieciński