Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions src/commands/moderation/giverole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { Command, CommandError, Constants, SwitchbladeEmbed } = require('../../')

module.exports = class Giverole extends Command {
constructor (client) {
super(client, {
name: 'giverole',
category: 'moderation',
requirements: { guildOnly: true, botPermissions: ['MANAGE_ROLES'], permissions: ['MANAGE_ROLES'] },
parameters: [{
type: 'member', acceptBot: true, missingError: 'commands:giverole.missingUser'
}, {
type: 'role', full: true, missingError: 'errors:invalidRole'
}]
})
}

async run ({ channel, member, author, t }, targetMember, role) {
const embed = new SwitchbladeEmbed(author)
try {
if (!member.hasPermission('ADMINISTRATOR', false, true, false)) {
if (member.highestRole.comparePositionTo(role) <= 0) throw new CommandError(t('commands:giverole.roleAboveAuthors'))
if (member.highestRole.comparePositionTo(targetMember.highestRole) <= 0) throw new CommandError(t('commands:giverole.roleBelow'))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This verification process should be made before adding the role to the target member.

And the condition in line 22 is non-sense, you are comparing member.highestRole to itself: member.highestRole.comparePositionTo(member.highestRole)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shit, I just changed the variable names and forgot this one lol.

await targetMember.addRole(role)
embed
.setTitle(t('commands:giverole.successTitle'))
.setDescription(`${targetMember} - \`${role.name}\``)
} catch (err) {
embed
.setColor(Constants.ERROR_COLOR)
.setTitle(t('commands:giverole.cantGiverole'))
.setDescription(`\`${err}\``)
}
channel.send(embed)
}
}
16 changes: 13 additions & 3 deletions src/locales/en-US/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -1115,12 +1115,12 @@
"notFound": "User not found.",
"noData": "Nothing found.",
"title": "{{user}}'s {{top}} in {{period}}",
"top":{
"top": {
"tracks": "top tracks",
"albums": "top albums",
"artists": "top artists"
},
"period":{
"period": {
"overall": "all time",
"7day": "a week",
"1month": "a month",
Expand Down Expand Up @@ -1416,10 +1416,20 @@
"commandDescription": "Shows a random image from r/CrappyDesign.",
"title": "Here's your crappy design."
},
"giverole": {
"commandDescription": "Gives a role to the target user",
"commandUsage": "<member> <role name>",
"missingUser": "You have to give me a member to this role!",
"noPermission": "I'm missing the **$t(permissions:MANAGE_ROLES)** permission give this role.",
"successTitle": "Role gived!",
"cantGiverole": "I can't give this role!",
"roleBelow": "Your role is below this member's",
"roleAboveAuthors": "You have to give me a role below yours!"
},
"goat": {
"commandDescription": "Shows a goat image from placegoat.com",
"commandUsage": "[width] [height]",
"hereIsYourGoat": "Here is your goat!",
"hereIsYourGoat_resolution": "Here is your **{{width}}x{{height}}** goat!"
}
}
}