我制作了一个名为clear的脚本。 该脚本可以正常工作。
但是我的清除脚本如何跳过频道中的固定消息?
这是我的脚本:
module.exports.run = async (bot, message, args) => {
if (message.deletetable) {
message.delete();
}
// Member doesn't have permission
if (!message.member.hasPermission("MANAGE_MESSAGES")) {
return message.channel.send("You can't delete messages...") // .then(m => m.delete(5000));
}
// Check if args[0] is a number
if (isNaN(args[0]) || parseInt(args[0]) <= 0) {
return message.channel.send("Yeah... That's not a number? I also can't delete 0 messages by the way.") // .then(m => m.delete(5000));
}
// Maybe the bot can't delete messages
if (!message.guild.me.hasPermission("MANAGE_MESSAGES")) {
return message.channel.send("Sorry... I can't delete messages.") // .then(m => m.delete(5000));
}
let deleteAmount;
if (parseInt(args[0]) > 100) {
deleteAmount = 100;
} else {
deleteAmount = parseInt(args[0]);
}
message.channel.bulkDelete(deleteAmount, true)
.then(deleted => message.channel.send(`I deleted \`${deleted.size}\` messages.`))
.catch(err => message.channel.send(`Something went wrong... ${err}`));
}
module.exports.help = {
name: "clear"
}
我希望有人可以帮助我,因为这将是我清晰脚本的不错补充。
答案 0 :(得分:1)
获取通道中的所有消息,然后固定消息,对filter
进行比较,仅保留非固定消息,然后删除这些消息。
client.on("message", async message => {
if (message.author.bot) return;
if (message.content === "/bulk") {
const allMessages = await message.channel.messages.fetch()
const deletable = allMessages.filter(message => !message.pinned)
await message.channel.bulkDelete(deletable, true)
}
});