我想要 nc!nuke #channel for bot 删除所有消息(不要频道,只有频道上的消息)

时间:2021-05-26 15:58:38

标签: python-3.x discord.py

谁有这方面的代码?

async def nuke(ctx, channel: discord.TextChannel = None):
    if channel == None: 
        await ctx.send("You did not mention a channel!")
        return

    nuke_channel = discord.utils.get(ctx.guild.channels, name=channel.name)

    if nuke_channel is not None:
        new_channel = await nuke_channel.clone(reason="Has been Nuked!")
        await nuke_channel.delete()
        await new_channel.send("THIS CHANNEL HAS BEEN NUKED!")
        await ctx.send("Nuked the Channel sucessfully!")

    else:
        await ctx.send(f"No channel named {channel.name} was found!")```

1 个答案:

答案 0 :(得分:0)

您将不得不使用 discord.TextChannel.purge() 函数。

channel # discord.TextChannel object (most likely the argument)
await channel.purge(limit=100) # Purge a certain amount of messages. You can choose

查看 purge() 函数 docs

相关问题