@Sigma_12313

Как сделать комманду для очистки чата Disnake?

Пытался сделать камманду для очистки чата в дискорд получилось не очень
выдаёт ошибку:
File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\slash_core.py", line 732, in invoke
    await call_param_func(self.callback, inter, self.cog, **kwargs)
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\params.py", line 1022, in call_param_func
    return await maybe_coroutine(safe_call, function, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\utils.py", line 600, in maybe_coroutine
    return await value
           ^^^^^^^^^^^
  File "C:\Users\Seregambo\Desktop\WTF\Новая папка\script.py", line 93, in clear
    await ctx.channel.purge ( limit = amount)
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\channel.py", line 617, in purge
    async for message in iterator:
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\iterators.py", line 117, in __anext__
    return await self.next()
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\iterators.py", line 316, in next
    await self.fill_messages()
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\iterators.py", line 338, in fill_messages
    if self._get_retrieve():
       ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\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:

Traceback (most recent call last):
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\interaction_bot_base.py", line 1377, in process_application_commands
    await app_command.invoke(interaction)
  File "C:\Users\Seregambo\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\slash_core.py", line 741, in invoke
    raise CommandInvokeError(exc) from exc
disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '>' not supported between instances of 'str' and 'int'


Вот код
@bot.slash_command( pass_context = True)
async def clear( ctx, amount = 100):
    await ctx.channel.purge ( limit = amount)
  • Вопрос задан
  • 517 просмотров
Решения вопроса 1
@KODYAcoder
Ошибка, которую вы получаете, связана с тем, что вы пытаетесь сравнить строку с целым числом, что не поддерживается.

Для решения этой проблемы вам нужно преобразовать аргумент "amount" в целое число, прежде чем передавать его в функцию "purge". Вы можете сделать это, используя функцию "int".

Измените ваш код на следующий образ:

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

Эта команда очистит чат на указанное количество сообщений (по умолчанию - 100). Вы можете вызвать эту команду, написав "/clear" в чате Discord и указав количество сообщений, которые вы хотите удалить, например "/clear 50".
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы
06 мая 2024, в 09:38
1200 руб./в час
06 мая 2024, в 09:37
1200 руб./в час
06 мая 2024, в 09:36
8000 руб./за проект