Aveyloff
@Aveyloff

Как поймать ошибку coldown в slash, disnake?

У меня не ловит декоратор @commands.cooldown(1, 30, BucketType.user), НО только с @commands.slash_command

В обработчике ошибок:
bot.py
@bot.event
async def on_command_error(ctx, error):
    print("#ERROR: ",error)
    if isinstance(error, disnake.ext.commands.errors.MissingPermissions):
        print("#ERROR: ",error)
        await ctx.reply("Ошибка: У вас недостаточно прав для использования данной команды.")
    if isinstance(error, disnake.ext.commands.errors.CommandOnCooldown):
            print("#ERROR: ",error)
            await ctx.reply("Ошибка: Повторите ошибку позже.")
    else:
        print("ERROR: ", error)
        raise error

Вот лог
disnake.ext.commands.errors.CommandOnCooldown: You are on cooldown. Try again in 8.97s


Через команды с префиксом работает.
  • Вопрос задан
  • 539 просмотров
Решения вопроса 1
fenrir1121
@fenrir1121 Куратор тега discord.py
Начни с документации
Потому что disnake работает и с обычными командами и со слеш.
Для слеш команд событие on_slash_command_error
@bot.event
async def on_slash_command_error(interaction: ApplicationCommandInteraction, error: Exception) -> None:
    """
    The code in this event is executed every time a valid slash command catches an error
    :param interaction: The slash command that failed executing.
    :param error: The error that has been faced.
    """
    pass
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы