【问题标题】:delete user messages in discord-rewrite.py删除 discord-rewrite.py 中的用户消息
【发布时间】:2019-11-04 22:45:15
【问题描述】:

这个命令应该做的是删除指定数量的消息,但我得到一个错误:

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)

【问题讨论】:

    标签: python discord discord.py discord.py-rewrite


    【解决方案1】:

    purge 实际上并没有收到要删除的消息列表(尽管文档的措辞好像确实如此)。相反,它需要一些关键字参数来确定是否应该删除消息。试试

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

    【讨论】:

      猜你喜欢
      • 2020-08-25
      • 2021-10-18
      • 2022-01-20
      • 2018-07-24
      • 2018-09-07
      • 1970-01-01
      • 2020-08-24
      • 2019-03-18
      • 2021-01-28
      相关资源
      最近更新 更多