#dont changing after 2 edits

1 messages · Page 1 of 1 (latest)

scarlet dawn
#

The bot stops changing the voice channel settings after exactly two changes. Moreover, the channel stops being deleted if there are 0 people in it (after 1 edit its working)

#

dont changing after 2 edits

heady jewel
#

maybe bcz rate limit

drowsy surge
#

Yeah you can only edit a channel 2 times per 10 minutes iirc

scarlet dawn
#

is there some opportunities to add cooldown for modal submit?

heady jewel
#

add cooldown for button

#
import disnake
from disnake.ext import commands

# Главный файл под строкой bot/client =
bot.cd_map = commands.CooldownMapping.from_cooldown(rate=1, per=10) 
# rate (int) - сколько раз за per(float) кол-во секунд

#Сама кнопочка:
@disnake.ui.button(
        label = "test button", style = disnake.ButtonStyle.blurple, custom_id = "one", emoji=":house_with_garden:"
    )
async def testbutton(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
    bucket = interaction.bot.cd_map.get_bucket(interaction) # Получаем bucket интеракции через объект бота (Return type: disnake.ext.commands.Cooldown)

    retry_after = bucket.update_rate_limit() # Получаем кулдаун (Return Type: float)

    if retry_after:
        await interaction.response.send_message(content=f"КД есть, осталось: {retry_after} секунд ", ephemeral=True)
    else:
        await interaction.response.send_message(content="Нет КД", ephemeral=True)```
scarlet dawn
scarlet dawn
heady jewel
#

try and see

scarlet dawn
#

dosent work

#

how to use this button in await channel.send?

drowsy surge
#

It's not going to work if you are creating a new cooldown every time the function is called.

heady jewel
#

yep

scarlet dawn
#

but how use this button here

drowsy surge
#

You don't.

#

the cooldown check should be in the button callback

heady jewel
#

so, u dont have any callbacks and u dont use views?

scarlet dawn
#

i need it, yes?

drowsy surge
#

You have button callbacks.

#

You're using listeners.

#

thats where your cd check should be.

scarlet dawn
#

or maybe

heady jewel
#

cd_channel? what a hell is that?

scarlet dawn
#

just rename

#

or i cannot do this

heady jewel
#

really?

scarlet dawn
#

I just used to use a cooldown for the command and was guided by this example, among other things

#

oh, wait

#

the same principle is literally used here, the cooldown just needs to be set outside the function

heady jewel
#

for slash command u can use decorator

scarlet dawn
heady jewel
#

pls dont do this shit

scarlet dawn
#

which one?

#

in slash command?

heady jewel
#

this kind of cooldown for slash command

scarlet dawn
#

ok, i remake it right now

heady jewel
#

-d commands.Bot.cooldown

true foxBOT
#

@disnake.ext.commands.cooldown(rate, per, type=BucketType.default)```
A decorator that adds a cooldown to a [`Command`](https://docs.disnake.dev/en/latest/ext/commands/api/prefix_commands.html#disnake.ext.commands.Command "disnake.ext.commands.Command")

A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns can be based either on a per-guild, per-channel, per-user, per-role or global basis. Denoted by the third argument of `type` which must be of enum type [`BucketType`](https://docs.disnake.dev/en/latest/ext/commands/api/checks.html#disnake.ext.commands.BucketType "disnake.ext.commands.BucketType").

If a cooldown is triggered, then [`CommandOnCooldown`](https://docs.disnake.dev/en/latest/ext/commands/api/exceptions.html#disnake.ext.commands.CommandOnCooldown "disnake.ext.commands.CommandOnCooldown") is triggered in [`on_command_error()`](https://docs.disnake.dev/en/latest/ext/commands/api/events.html#disnake.ext.commands.on_command_error "disnake.ext.commands.on_command_error") and the local error handler.

A command can only have a single cooldown.
scarlet dawn
#

how to properly handle this error?

heady jewel
#

you need error handler for slash command

#

-d on_slash_command_error

true foxBOT
#

disnake.ext.commands.on_slash_command_error(inter, error)```
An error handler that is called when an error is raised inside a slash command either through user input error, check failure, or an error in your own code.

A default one is provided ([`Bot.on_slash_command_error()`](https://docs.disnake.dev/en/latest/ext/commands/api/bots.html#disnake.ext.commands.Bot.on_slash_command_error "disnake.ext.commands.Bot.on_slash_command_error")).
scarlet dawn
#

Thank you, I just found it, I had to add one word