如何从频道中删除 n 条消息?

How to delete n messages from a channel?

我正在开发一个不和谐的机器人。我想实现像 Tatsumaki 的 t!prune 5 这样的功能(从历史记录中删除 5 条消息)。

好的,让我用一种或另一种方式告诉你我的意思:

msg.channel.delete(2); // 2 is the number of messages being deleted.
                       // this is not a real function, just an example

有没有像我展示的这样的东西?

尝试使用以下

const fetchedMessages = await msg.channel.fetchMessages();
const amount = 50 // number of messages that should be deleted (max 50 otherwise you have to change the option limit property for .fetchMessages())



for (let i = 0; i < amount; i++) {
await fetchedMessages[i].delete()
}

您还可以使用 .bulkDelete() 函数:

await msg.channel.bulkDelete(AMOUNT)