pythondiscordnextcord

slash commands visible by role, user or permissions


If I have commands for special roles (e.g. /ban, /kick, /mute), every user can see them. It would be possible to display these commands only for those users who can execute them?

You could check for permissions, roles, or id, but then people would still see these commands in the list


Solution

  • You can prevent users without the required permissions from seeing a command, by using the default_member_permissions parameter found here, when creating slash commands.

    @client.slash_command(name="ping", description="Ping the bot", default_member_permissions=(nextcord.Permissions(administrator=True)))
    async def ping(interaction: nextcord.Interaction):
        await interaction.send("Pong!", ephemeral=True)
    

    You can allow and deny certain users and roles from seeing specific commands in the server settings.
    To do so, go to Server Settings -> Integrations -> Bot/Application and click the command you want to configure roles and members for.

    allow/deny certain roles and users