'discord.py slash permissions

How to add permissions to discord.py slash-commands command? There is no @has_permissions() in slash-commands.

@slash.slash(
    name="kick",
    description="Kicks member from the server",
    options=[manage_commands.create_option(
        name = "member",
        description = "Who do you want to kick?",
        option_type = 3,
        required = True
        ),
        manage_commands.create_option(
        name = "reason",
        description = "What is the reason?",
        option_type = 3,
        required = False
        )])
async def _kick(ctx, member: discord.Member, reason='Unspecified'):
    await ctx.send(0)
    await member.kick(reason=reason)
    e=discord.Embed(title="🔨 Banhammer has spoken", color=0xfa2d4c)
    e.add_field(name='Kick', value=f' :white_check_mark: Kicked {member} for `{reason}`', inline=False)
    await ctx.channel.send(embed=e)```


Solution 1:[1]

Since there is currently no permissions check for (discord-py-slash-command)[https://pypi.org/project/discord-py-slash-command/], you can check within of your code if a member has a certain permission, as shown below

@slash.slash(name="cool_command")
async def cool_command(ctx, option):
    if not ctx.author.guild_permissions.manage_messages: # replace this with your desired permission
        return # tell them they dont have permissions or raise an exception
    ... # do your stuff here

Solution 2:[2]

Discord.py does not support slash commands yet. Meanwhile, you can use discord-py-slash-command to use slash-commands. Hope this helped

Solution 3:[3]

Well, I tried out using @commands.has_permissions() and in my case it still worked. You can just try it out with a test command, it should respond:

Interaction Failed

Let me know if it's not like that to you

Solution 4:[4]

Now that there is slash command permissions when you generate your ouath2 token to invite the bot instead of just adding "bot" add "bot" and "applications.commands"

Discord.py has no actual support for slash command with just there api but theres a different one download here:

https://pypi.org/project/discord-py-slash-command/

Solution 5:[5]

Below @slash.slash(name=“Kick”, description=“Kicks the member”)

Add:

@commands.has_permissions(kick_members=True)

There you go. It should work

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nite Block
Solution 2 CUPZYY
Solution 3 Muhammad Dyas Yaskur
Solution 4 palmtrww
Solution 5 RiveN