xxxxxxxxxx
/*
Need more help? Add me on discord: Dwagon#0069
Discord.js ^13.8.1
*/
/*
With interaction
*/
// Get interaction user option & member
const user = interaction.options.getUser("user");
const member = interaction.guild.members.cache.get(user.id) || await interaction.guild.members.fetch(user.id).catch(err => { });
// Get role with ID
const roleToGive = interaction.guild.roles.cache.get("123456789123456789")
// Find role with name
const roleToGive = interaction.guild.roles.cache.find(role => role.name === "Member")
// Add role to member
member.roles.add(roleToGive)
/*
With message
*/
// Get interaction user option & member
const member = message.mentions.members.first();
// Get role with ID
const roleToGive = message.guild.roles.cache.get("123456789123456789")
// Find role with name
const roleToGive = message.guild.roles.cache.find(role => role.name === "Member")
// Add role to member
member.roles.add(roleToGive)
xxxxxxxxxx
// find the role with the name "Community"
let role = message.guild.roles.find(r => r.name == 'Community')
// if role doesn't exist, notify the author of command that the role couldn't be found
if (!role) return message.channel.send(`**${message.author.username}**, role not found`)
// find all guild members that aren't bots, and add the "Community" role to each
message.guild.members.filter(m => !m.user.bot).forEach(member => member.addRole(role))
// notify the author of the command that the role was successfully added to all members
message.channel.send(`**${message.author.username}**, role **${role.name}** was added to all members`)
xxxxxxxxxx
// deleting the channels overwrite for the message author
channel.permissionOverwrites.get(message.author.id).delete();
xxxxxxxxxx
channel.updateOverwrite(channel.guild.roles.everyone, { VIEW_CHANNEL: false });