#dont changing after 2 edits
1 messages · Page 1 of 1 (latest)
maybe bcz rate limit
Yeah you can only edit a channel 2 times per 10 minutes iirc
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)```
спасибо
try and see
It's not going to work if you are creating a new cooldown every time the function is called.
oh, exactly
yep
but how use this button here
so, u dont have any callbacks and u dont use views?
no(
i need it, yes?
You have button callbacks.
You're using listeners.
thats where your cd check should be.
cd_channel? what a hell is that?
really?
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
for slash command u can use decorator
that was easiest way i found, when i creat this command
pls dont do this shit
this kind of cooldown for slash command
ok, i remake it right now
-d commands.Bot.cooldown
@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.
how to properly handle this error?
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")).
Thank you, I just found it, I had to add one word