удалить сообщения пользователя в discord-rewrite.py - PullRequest
0 голосов
/ 27 июня 2018

Предполагается, что эта команда удалит указанное количество сообщений, но вместо этого я получаю сообщение об ошибке:

Ignoring exception in command clear:
Traceback (most recent call last):
  File "C:\Users\dimit\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "c:/Users/dimit/Desktop/Discord Bot Shit/BasicBot.py", line 54, in clear
    await channel.purge(messages)
TypeError: purge() takes 1 positional argument but 2 were given

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\dimit\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 886, in invoke
    yield from ctx.command.invoke(ctx)
  File "C:\Users\dimit\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 498, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\dimit\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 71, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: purge() takes 1 positional argument but 2 were given

Код, который я пробовал:

@bot.command()
async def clear(ctx,amount):
    channel = ctx.message.channel
    messages = []
    async for message in channel.history(limit=int(amount)):
        messages.append(message)
        await channel.purge(messages)

1 Ответ

0 голосов
/ 27 июня 2018

purge фактически не получает список сообщений для удаления (хотя документация сформулирована так, как если бы она была). Вместо этого он принимает ряд ключевых аргументов, которые он использует, чтобы определить, следует ли удалять сообщения. Попробуйте

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