我是 javascript 编程的新手。我在 discord 上有一个机器人,它的一个命令是让通话中的每个人都静音,但是当调用该命令时,它会使五个用户静音,造成延迟,然后立即使其余用户静音我如何才能消除这种延迟为什么会这样
这是命令的代码
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
if (!message.member.hasPermission('MANAGE_MESSAGES'))
return message.channel.send("You don't have this permission!");
let muteRole = message.guild.roles.cache.find(
(role) => role.name === '🔇 Sshhhhhhh'
);
let channel = message.member.voice.channel;
let user = message.author;
if (args[0] === 'all') {
channel.members.forEach(function(guildMember, guildMemberId) {
guildMember.roles.add(muteRole.id);
});
message.delete().catch((O_o) => {});
message.channel.send(`${user.username} silenced everyone.`);
return;
} else if (args[0] == null) {
message.delete().catch((O_o) => {});
message.channel.send(`${user.username} is silent.`);
message.member.roles.add(muteRole.id);
return;
}
let person = message.guild.member(
message.mentions.users.first() || message.guild.members.get(args[1])
);
if (!person) return message.channel.send("Couldn't find that member");
else {
message.delete().catch((O_o) => {});
message.channel.send(`${user.username} silenced ${person}.`);
person.roles.add(muteRole.id);
}
};
使所有人沉默的命令在第 14 和 15 行
channel.members.forEach(function(guildMember, guildMemberId) {
guildMember.roles.add(muteRole.id);
});
森栏
相关分类