Skip to content

Commit

Permalink
[Update] fixed a typo in addrole and updated removerole
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Oct 5, 2021
1 parent eb61ca9 commit 4369cb7
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commands/Admin/addrole.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { getGuildUserFromMention } = require("../../modules/getUserFromMention");
module.exports = {
name: "addrole",
args: true,
description: "Ddds a role for a user",
description: "Adds a role for a user",
usage: "addrole <user> <role name>",
async run(message, args, client) {
const guildUser = getGuildUserFromMention(args[0], message);
Expand Down
89 changes: 89 additions & 0 deletions commands/Admin/removerole.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,97 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { Permissions } = require("discord.js");
const { embedMessage } = require("../../modules/embedSimple");
const { getGuildUserFromMention } = require("../../modules/getUserFromMention");

module.exports = {
name: "removerole",
args: true,
description: "Removes a role from a user",
usage: "removerole <user> <role name>",
async run(message, args, client) {
const guildUser = getGuildUserFromMention(args[0], message);
const roleName = args[1];
const roleToGive = message.guild.roles.cache.find(
(role) => role.name === `${roleName}`
);

if (!args[0])
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`❌ | Please mention a user to remove the role!`
),
],
});

if (!roleName)
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`❌ | Please enter the role name you wish to remove`
),
],
});

if (!roleToGive)
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`❌ | I did not find this role!\nplease make sure to enter a valid role name! (case sensitive)`
),
],
});

if (
!message.member.permissions.has("ADMINISTRATOR") ||
!message.member.permissions.has("MANAGE_ROLES")
)
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`❌ | You do not have permission to remove roles!`
),
],
});

try {
await guildUser.roles.remove(roleToGive);
await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`✅ | ${roleToGive} has been removed from ${guildUser}`
),
],
});
} catch (err) {
client.logger(err.message, "error");
if (err.message === "Missing Access") {
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`❌ I do not have adminstraitor permission!`
),
],
});
}
if (err.message === "Missing Permissions") {
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`❌ I can not add this role to the user!\nEtiher its above me or I have no right to assign it to other users!`
),
],
});
}
}
},
data: new SlashCommandBuilder()
.setName("removerole")
.setDescription("removes a role for a user")
Expand Down

0 comments on commit 4369cb7

Please sign in to comment.