Как добавить команду в slash_command?

Рейтинг: 0Ответов: 1Опубликовано: 15.06.2023

Я создал slash команду для удаление сообщение в дискорд-сервере. Но она не работает.

    @bot.slash_command(description='Эта команда может удалять сообщения в чате.')
    async def clear(ctx, amount=100):
        # amount = int('1') # пробовал так, но тоже не работает
        await ctx.channel.purge(limit=amount)

Работает только так, НО я так не хочу.

    @bot.command()
    async def clear(ctx, amount=100):
        await ctx.channel.purge(limit=amount)

Выводит вот такую ошибку:

    File "C:\Users\maksi\PycharmProjects\DS-BOT\venv\lib\site- 
    packages\disnake\iterators.py", line 325, in _get_retrieve
      if limit is None or limit > 100:
    TypeError: '>' not supported between instances of 'str' and 'int'
    The above exception was the direct cause of the following exception:
    
    disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: 
    TypeError: '>' not supported between instances of 'str' and 'int'

Ответы

▲ 0Принят

Мне уже не нужна помощь с этой проблемой. Я нашёл решение этой проблемы. Вот она:

@bot.slash_command(description='Описание')
async def clear(ctx, amount: int): # поменял значение amount на int
    await ctx.channel.purge(limit=amount)

И после этого у меня всё работает)