我正在尝试制作反垃圾邮件,并且当该漫游器应该为每个频道编辑静音角色的权限时,
所以我首先创建角色
const mute_role = message.guild.roles.cache.find(r => r.name == "Muted");
if (!mute_role) {
try {
mute_role = await message.guild.roles.create({
data: {
name: "Muted",
color: "#000000",
permissions: []
}
})
然后我在所有公会频道上编辑角色的权限
message.guild.channels.cache.forEach(async (channel, id) => {
await channel.updateOverwrite(mute_role,
{
SEND_MESSAGES: false,
ADD_REACTIONS: false,
}
);
});
} catch (e) {
console.log(e.stack);
}
}
执行完此操作后,它应该继续执行其余代码,但似乎跳过了这一部分,因为它继续处理反垃圾邮件,并在触发垃圾邮件时添加了角色
这是反垃圾邮件的完整代码
bot.on('message', async message => {
if (message.author.bot) return;
const mute_role = message.guild.roles.cache.find(r => r.name == "Muted");
if (!mute_role) {
try {
mute_role = await message.guild.roles.create({
data: {
name: "Muted",
color: "#000000",
permissions: []
}
})
message.guild.channels.cache.forEach(async (channel, id) => {
await channel.updateOverwrite(mute_role,
{
SEND_MESSAGES: false,
ADD_REACTIONS: false,
}
);
});
} catch (e) {
console.log(e.stack);
}
}
if (usersMap.has(message.author.id)) {
const userData = usersMap.get(message.author.id);
const { lastMessage, timer } = userData;
const difference = message.createdTimestamp - lastMessage.createdTimestamp;
let msgCount = userData.msgCount;
console.log(difference);
if (difference > DIFF) {
clearTimeout(timer);
console.log('Cleared timeout');
userData.msgCount = 1;
userData.lastMessage = message;
userData.timer = setTimeout(() => {
usersMap.delete(message.author.id);
console.log('Removed from RESET');
}, TIME);
usersMap.set(message.author.id, userData);
}
else {
msgCount++;
console.log(msgCount)
if (parseInt(msgCount) === LIMIT) {
message.member.roles.add(mute_role);
message.channel.send(`${message.author} has been muted for spamming`);
setTimeout(() => {
message.member.roles.remove(mute_role);
message.channel.send(`${message.author} has been unmuted`);
}, TIME);
}
else {
userData.msgCount = msgCount;
usersMap.set(message.author.id, userData);
}
}
}
else {
let fn = setTimeout(() => {
usersMap.delete(message.author.id);
console.log('Removed from map');
}, TIME);
usersMap.set(message.author.id, {
msgCount: 1,
lastMessage: message,
timer: fn
})
}
})