const { MessageEmbed } = require('discord.js')
module.exports = {
name: "addrole",
aliases: ["role", "P!role"],
category: "moderation",
description: "Add role to any user",
run: async (client, message, args) => {
if (!message.member.hasPermission("MANAGE_ROLES")) {
return message.channel.send("sorry you need permission to mute someone");
}
if (!message.guild.me.hasPermission("MANAGE_ROLES")) {
return message.channel.send("I do not have the permissions");
}
const targets = message.mentions.members;
if(!targets.first()) return message.reply(`<:no:677902165859237894>please mention user!`)
let arole = message.mentions.roles.first();
if(!arole) return message.reply(`<:no:677902165859237894>please mention role for add!`)
const embed = new MessageEmbed()
.setColor("RANDOM")
.setDescription(`<a:ok_:731369076315652167>role added ${arole}`)
await message.channel.send(embed)
targets.forEach(target => target.roles.add(arole));
}
}
This adds role to the mentioned users.
Instead is there a way to alter
const targets = message.mentions.members
Such that the targets are all server members? And then by foreach, I can give the role to all the targets.
question from:
https://stackoverflow.com/questions/66057606/a-code-to-add-a-role-to-all-members-of-the-server 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…