【发布时间】:2019-06-13 12:40:47
【问题描述】:
我正在尝试使用我的机器人删除特定频道中的旧消息。
下面的代码不起作用,我不知道为什么。
if (msg.channel == channelDLid) {
msg.delete(6000);
}
代码已执行,但没有做任何事情。
【问题讨论】:
标签: node.js bots discord discord.js
我正在尝试使用我的机器人删除特定频道中的旧消息。
下面的代码不起作用,我不知道为什么。
if (msg.channel == channelDLid) {
msg.delete(6000);
}
代码已执行,但没有做任何事情。
【问题讨论】:
标签: node.js bots discord discord.js
如果你想用 id 检查频道,你应该写:
if (msg.channel.id == channelDLid) {
msg.delete(6000);
}
【讨论】:
您可以使用Channel#bulkDelete,它允许您删除最多 2 周前的消息。
要仅删除特定消息,您可以使用Channel#fetchMessages,例如:
const messages = await message.channel.fetchMessages({ limit: 100}) // Fetch last 100 messages
.then(msgs => msgs.first(msgs.size - 3)) // Remove the last 3 messages out of the collection to delete
message.channel.bulkDelete(messages, true);
【讨论】: