woomy/src/commands/takerole.js

86 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> No user specified. Usage: \`${client.commands.get(`takerole`).help.usage}\``
);
}
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];
}
let role = role2add.join(" ");
2020-03-09 01:11:33 +00:00
gRole = client.findRole(role, 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 take 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 can't take 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 don't have that role!"
);
}
2020-03-09 01:11:33 +00:00
await user.roles.remove(gRole.id);
2020-01-25 10:02:43 +00:00
message.channel.send(
`<:success:466995111885144095> Took the \`${gRole.name}\` role from \`${
user.user.tag
}\``
);
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("#008369");
2020-03-09 01:11:33 +00:00
embed.setAuthor("Role taken:", user.user.avatarURL({format: "png", dynamic: true}));
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: ["removerole"],
permLevel: "Moderator",
requiredPerms: ["MANAGE_ROLES"]
};
exports.help = {
name: "takerole",
category: "Moderation",
description: "Takes a role from the specified user.",
usage: "takerole [user] [role]"
};