我如何从服务器内部的每个用户中删除角色,我尝试使用let everyone = message.guild.members.get
和let everyone = message.guild.members
,但是它们都没有作用。
这是整个代码:
const Discord = require("discord.js");
const errors = require("../utils/errors.js");
module.exports.run = async(bot, message, args) => {
if (!message.member.hasPermission("MANAGE_ROLES")) return errors.noPerms(message, "MANAGE_ROLES");
let role = message.guild.roles.find(`name`, `NSFW`);
let everyone = message.guild.members.get
if (args[0] == "help") {
message.reply("Usage: !nsfwoff");
return;
message.channel.send(`NSFW has been turned to OFF, you're now safe from any kind of explicit content!`)
}
await (everyone.removeRole(role.id))
.then(role => console.log(`NSFW OFF: ${message.guild.name}`))
.catch(console.error);
message.channel.send(`NSFW has been turned to ON, try !nsfwget to get the NSFW role!`);
}
module.exports.help = {
name: "nsfwoff"
}
答案 0 :(得分:0)
只需使用.forEach()
函数。
const Discord = require('discord.js');
module.exports.run = async (bot, message, args) => {
if(!message.member.hasPermission('MANAGE_ROLES')) return noPermissions();
let role = message.guild.roles.find(t => t.name == 'NSFW')
message.guild.members.forEach(member => {
if(!member.roles.find(t => t.name == 'NSFW')) return;
member.removeRole(role.id);
.then(function() {
console.log(`Removed role from user ${member.user.tag}!`);
})
})
}