Skip to content

Slash Command Permissions #2315

Closed
Closed
@maanex

Description

@maanex

Description

Allow slash commands to be only executed when a user has specific permissions in the channel they're using the command in. These permissions can be set individually for each slash command, allowing moderator only slash commands for instance.

Why This is Needed

While it is possible to check permissions after a user has sent a command and reply with a "you don't have the permission to execute this command" type of text, having unusable commands hidden in the ui entirely would resolve in both, a better user experience, and less server side (bot, not discord) code.

Example use cases where this would be useful:

  • a /warn command that kicks users with 3 warnings should only be executable by users with the "kick members" permission
  • a /bulkdelete command to delete multiple messages at once should only be executable by users with the "manage messages" permission

Alternatives Considered

Alternative would be to manually check the permissions on each slash command execution. This works currently but has two major downsides:

  • the command is still visible in the user interface and auto-completes without letting the user know they can't use the command
  • extra server side code for permission checks is required (and possibly even having a bot in the same guild)

Additional Details

Taking the example JSON object from the documentation, a simple "permission" attribute with a bitfield as the minimum required permissions would be how I imagine to set these permission requirements:

json = {
    "name": "blep",
    "description": "Send a random adorable animal photo",
    "permission": 0b10000000000110, // Permission bits as seen everywhere else in the app. The user would have to have all of those permissions in order to use the command.
    "options": [
        {
            "name": "animal",
            "description": "The type of animal",
            "type": 3,
            "required": true,
            "choices": [
                {
                    "name": "Dog",
                    "value": "animal_dog"
                }
            ]
        },
    ]
}

Additional/custom permission checks (like having a specific role) would still need manual permission checks and "no permission" responses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plannedWe're going to fix this pretty soonslash commandssyncedSynced to internal tracker

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions