机器人可以删除DM上的消息吗

时间:2020-10-11 17:49:36

标签: python discord discord.py

因此,我正在尝试执行clear_dm命令。我尝试了很多方法,但是没有。也许你们知道该怎么做。

我将展示我的代码:

@client.command()
async def clear_dm(ctx, arg : int):
    dm = discord.DMChannel
    await ctx.authordm.purge(limit=arg)
    await ctx.message.delete()
    await ctx.send(f'{ctx.author}, your dm with me has been cleared.', delete_after=4)

我希望你能帮助我:)

1 个答案:

答案 0 :(得分:1)

DMChannel没有清除方法,您不能删除dm通道中其他用户发送的消息。但是,如果您想清除漫游器的消息,则可以执行以下操作:

dmchannel = #dm channel you want to clear
async for message in dmchannel.history(limit=100):
    if message.author == client.user: #client.user or bot.user according to what you have named it
        await message.delete()