UNPKG

free-code

Version:

Makes free code for discord.js command/bots

28 lines (23 loc) 1.61 kB
const { Message } = require('discord.js') module.exports = { name: 'addrole', /** * @param {Message} message */ run: async (client, message, args) => { if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send('You do not have permission.'); if (!message.guild.me.hasPermission("MANAGE_ROLES")) return message.channel.send('I do not have permission.') const target = message.mentions.members.first() || message.guild.members.cache.get(args[0]) //member = mentions or id if (!target) return message.channel.send('No member specified') //when no member is pinged or given if (message.member.roles.highest.position > message.guild.me.roles.highest.position) return message.reply('The roles of the target is higher than yours!'); if (message.member.roles.highest.position > target.roles.highest.position) return message.reply('Your roles are higher than mine!!'); const role = message.mentions.roles.first() || message.guild.roles.cache.get(args[1]) // roles = mentions or id if (!role) return message.channel.send('No role specified') //when no role is specified or pinged if (!message.guild.roles.cache.has(role)) return message.channel.send('That role does not exist in this server!') await target.roles.add(role) // adding the role to the user target.send(`You have obtained the **${role.name}** role in the **${message.guild.name}** server!`) message.channel.send(`${target.user.username} has obtained the <@&${role.id}> role!`) } }