woomy/src/commands/giverole.js

88 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-01-25 10:02:43 +00:00
exports.run = async (client, message, [member, ...role2add], query) => {
if (!member) {
return message.channel.send(
"<:error:466995152976871434> Who am I meant to give a role?"
);
}
let user = message.mentions.members.first();
let users;
if (!user) {
users = client.searchForMembers(message.guild, member);
if (users.length > 1)
return message.channel.send(
"<:error:466995152976871434> Found multiple users! Please be more specific or mention the user instead."
);
else if (users.length == 0)
return message.channel.send(
"<:error:466995152976871434> That user doesn't seem to exist. Try again!"
);
user = users[0];
}
2020-03-09 01:11:33 +00:00
let joinedValue = role2add.join(" ");
let gRole = client.findRole(joinedValue, message);
2020-01-25 10:02:43 +00:00
if (!gRole) {
return message.channel.send(`<:error:466995152976871434> That role doesn't seem to exist. Try again!`);
2020-03-09 01:11:33 +00:00
};
2020-01-25 10:02:43 +00:00
let moderator = message.guild.member(message.author)
2020-03-09 01:11:33 +00:00
if (gRole.position >= moderator.roles.highest.position) {
2020-01-25 10:02:43 +00:00
return message.channel.send(
"<:error:466995152976871434> You cannot give roles higher than your own!"
);
}
2020-03-09 01:11:33 +00:00
var bot = message.guild.members.cache.get(client.user.id)
if (gRole.position >= bot.roles.highest.position) {
2020-01-25 10:02:43 +00:00
return message.channel.send(
`<:error:466995152976871434> I cannot give roles higher than my own!`
);
}
2020-03-09 01:11:33 +00:00
if (user.roles.cache.has(gRole.id)) {
2020-01-25 10:02:43 +00:00
return message.channel.send(
"<:error:466995152976871434> They already have that role!"
);
}
2020-03-09 01:11:33 +00:00
await user.roles.add(gRole.id);
2020-01-25 10:02:43 +00:00
message.channel.send(
`<:success:466995111885144095> Gave \`${user.user.tag}\` the \`${gRole.name}\` role.`
);
if (client.getSettings(message.guild.id).modlogsChannel !== "off") {
2020-03-09 01:11:33 +00:00
const channel = message.guild.channels.cache.find(
2020-01-25 10:02:43 +00:00
channel => channel.name === client.getSettings(message.guild.id).modlogsChannel
);
if (channel) {
2020-03-09 01:11:33 +00:00
let embed = new Discord.MessageEmbed();
2020-01-25 10:02:43 +00:00
embed.setColor("#00c09a");
2020-03-16 01:21:19 +00:00
embed.setAuthor("Role given:", user.user.avatarURL({format: "png", dynamic: true, size: 2048}));
2020-03-09 01:11:33 +00:00
embed.setDescription(`‏‏‎• User: ${user} (${user.user.id})\n‏‏‎• Mod: ${message.author} (${message.author.id})\n‏‏‎• Role: ${gRole}`)
2020-01-25 10:02:43 +00:00
try {
channel.send({ embed });
} catch (err) {
// probably no permissions to send messages/embeds there
};
};
};
};
exports.conf = {
enabled: true,
guildOnly: true,
aliases: ["addrole"],
permLevel: "Moderator",
requiredPerms: ["MANAGE_ROLES"]
};
exports.help = {
name: "giverole",
category: "Moderation",
description: "Gives the user the specified role.",
usage: "giverole [user] [role]"
};