#πŸ”’ Permissions Check

28 messages Β· Page 1 of 1 (latest)

plucky basin
#

I have a discord bot py.

I have a cog file and in that file I already have a class. Within that class I have commands with @app_commands.commands().

I have a database with guilds as key and roles as keys for each guild. The roles are the ones that are permitted to access the commands.

I want to setup the commands in a way that only those authorized can view the slash commands on the dashboard.

Like dyno. Only people who are permitted to use it can view the command on the application command dashboard.

How do I do this?

valid canopyBOT
#

@plucky basin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

plucky basin
#

Example of what I mean attached below. Since I can't use it, I can't see the ban command.

wispy ice
plucky basin
#

Yh. Maybe.

wispy ice
#

theres also some property to check permissions so like for a purge i can check for edit messages or what perm

plucky basin
#

I need some help building the code for it

wispy ice
#

any(roleid == role.id for role in discord.Interaction.user.roles)

plucky basin
#

Yh I mean that's understandable but you need a decorator to prevent unauthorised users viewing it.

#

I need help making that.

wispy ice
plucky basin
#

Yeah I understand. But to prevent it from appearing on the dashboard.

#

You need a decorator I think.

wispy ice
#

!d discord.app_commands.default_permissions

valid canopyBOT
#

@discord.app_commands.default_permissions(perms_obj=None, /, **perms)```
A decorator that sets the default permissions needed to execute this command.

When this decorator is used, by default users must have these permissions to execute the command. However, an administrator can change the permissions needed to execute this command using the official client. Therefore, this only serves as a hint.

Setting an empty permissions field, including via calling this with no arguments, will disallow anyone except server administrators from using the command in a guild.

This is sent to Discord server side, and is not a [`check()`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.check). Therefore, error handlers are not called.

Due to a Discord limitation, this decorator does nothing in subcommands and is ignored.
wispy ice
#

found this

plucky basin
# wispy ice found this

That's normal permissions like manage_roles or manage_server. Like server permissions.

It's a giveaway bot what I have and the command /giveawaycreate should only be seen by people with the roles from the mongo db.

wispy ice
#

!d discord.app_commands.checks.has_role

valid canopyBOT
#

@discord.app_commands.checks.has_role(item, /)```
A [`check()`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.check) that is added that checks if the member invoking the command has the role specified via the name or ID specified.

If a string is specified, you must give the exact name of the role, including caps and spelling.

If an integer is specified, you must give the exact snowflake ID of the role.

This check raises one of two special exceptions, [`MissingRole`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.MissingRole) if the user is missing a role, or [`NoPrivateMessage`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.NoPrivateMessage) if it is used in a private message. Both inherit from [`CheckFailure`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.CheckFailure).

New in version 2\.0\...
wispy ice
#

but i dont think this hides it

#

maybe use a combo

plucky basin
#

Hmm. Could someone help clear this up?

valid canopyBOT
#

@discord.app_commands.default_permissions(perms_obj=None, /, **perms)```
A decorator that sets the default permissions needed to execute this command.

When this decorator is used, by default users must have these permissions to execute the command. However, an administrator can change the permissions needed to execute this command using the official client. Therefore, this only serves as a hint.

Setting an empty permissions field, including via calling this with no arguments, will disallow anyone except server administrators from using the command in a guild.

This is sent to Discord server side, and is not a [`check()`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.check). Therefore, error handlers are not called.

Due to a Discord limitation, this decorator does nothing in subcommands and is ignored.
tepid ravine
#

you can also use this to restrict by default who can see and use it, however admins can change these settings so the body of that command must not rely on the permission being true

valid canopyBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.