我希望创建一个命令来清除聊天,同时还将聊天中清除的内容记录到只有 Mods/Admins 及以上级别的 mod-logs channel 中。
我正在寻找类似于 Dyno BOT 的清除命令的东西,但没有 Web 应用程序方面的东西。
我的代码也是这样的:
if(command==="purge){
message.delete()// This deletes the command
// CODE GOES HERE
}else{
// This mentions the commanding person if they do not have the following permission MANAGE_MESSAGES
message.reply("Nice try, you do not have MANAGE_MESSAGES permission.")
}
}
最佳答案
我认为唯一的选择是使用channel.fetchMessages,并在删除之前发送每条消息。
这个例子可能有效:
async function purgeMessages(count, channel, logChannel) {
const messages = await channel.fetchMessages({ limit: count }).catch(console.error);
for (const message of messages.values()) {
await logChannel.send(message.content).catch(console.error);
await message.delete().catch(console.error);
}
}
请注意,这不会发送附件或嵌入内容。如果您也想发送这些内容,则需要循环 message.embeds
和 message.attachments
。
另一个选择可能是监视 the messageDeleteBulk event ,并使用类似的方法发送已删除的消息。
关于javascript - 我如何创建一个清除命令来记录已清除内容的 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51781723/