删除特定频道中的消息
Delete message in a specific channel
我正在尝试使用我的机器人删除特定频道中的旧消息。
下面的代码不起作用,我不知道为什么。
if (msg.channel == channelDLid) {
msg.delete(6000);
}
代码已执行,但未执行任何操作。
如果要查看频道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);
我正在尝试使用我的机器人删除特定频道中的旧消息。
下面的代码不起作用,我不知道为什么。
if (msg.channel == channelDLid) {
msg.delete(6000);
}
代码已执行,但未执行任何操作。
如果要查看频道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);