#help with permissions (discord bot)

15 messages · Page 1 of 1 (latest)

wanton furnace
#

We would need to see your code. If it is very specific to the discod.js API, they also have a dedicated server that may end up having more information. But if it is a general question, someone here should be able to help 🙂

wanton furnace
#

!!discord.djs

latent spokeBOT
#

Looking for help with Discord.js?
If you are asking about discord.js and not getting help, try this server!
https://discord.gg/bRCvFy9

marsh hill
#

You should give your comman structures a "permission" field, where you specify the permissionr equired for the command.

#

Then when you get the command, before executing it, you check for the permission.

#

If you're talking about slash commands, then you set that for each one.

marsh hill
#

Then my initial reply applies

marsh hill
#

Right, so if you're using your commands permission property to determine required permissions, then you can simply set the required permission on each command.
So for whatever commands you don't want to have the manage messages permission, then just don't have it set?

#

And if you want to make it easier and not have to repeat the permission property on all of the ones that require manage messages, then use an inheritance structure.

#

Then you should start with something simple and learn the fundamentals first.
If you're asking technical questions you will get technical answers, and it is expected that your'e familiar with certain terminology and concepts, before you start working on more complex ones.

I usually recommend people learn and understand the following concepts to start with:
variable declaration and variable assignment, and reassignment.
var/let/const - the differences, when and why to use them.
primitive types
function signatures and invocation.
Parameters and arguments
Scope
Function returns
Boolean expressions and order of operations
if statements and control flow
Loops (for, while, do)
objects
classes, instances
I'd recommend https://javascript.info/ for learning

#

Do you have a code snippet of how you're currently doing it?
Provide:

  1. An example of your command with the permission property (which you said you have)
  2. The code where you're checking that permission.
marsh hill
#

I don't see a .permission property, which you just said you had on your commands.
You should be doing something like this:

if (command) {
    if (command.permission && !message.guild.me.hasPermission(command.permission)) {
        // bot does not have permission
        return;
    }
    // Command found and permission available here
} else {
    // Command not found
}

Also, this is good that you're checking that your bot has the necessary permission to run the command.
But what about the user who sent the command?
Do you want a user who does not have permission to manage messages, to be able to manage messages via your bot?

#

Usually, in that case, people make it so that guild owners / admins can configure a role with the bot, and then only members with that role can send certain commands. You could also have multiple configurable roles and use them for different kinds of commands.

#

You could even go as far as making it so that guild owners / admins can configure each one of your bots commands to only be used by members with a selected role.

#

But all of this is also handled for you automatically if you use slash commands, and so you don't even need to write any code to have that functionality