E
E
Evgeny Nikitenko2021-05-22 10:56:01
Python
Evgeny Nikitenko, 2021-05-22 10:56:01

How to make commands in python discord bot available only to server admin?

it is necessary that some commands entered by a regular user of the server be inaccessible to him.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2021-05-22
@no_SNITCH

There are many options, even inside a function with command processing, even with a decorator. I think a decorator would be better. Discordpy has a special decorator for this, so you don't have to come up with your own.

@commands.has_guild_permissions(administrator=True)

If the check fails - the code throws an exception, so it will need to be caught
from discord.ext import commands

@bot.command()
@commands.has_guild_permissions(administrator=True)
async def test(ctx):
    ctx.send('hello world')


@test.error
async def test_error(ctx, error):
    if isinstance(error, commands.errors.MissingPermissions):
        await ctx.send('Недостаточно прав')

Y
Yupiter7575, 2021-05-22
@yupiter7575

Have you heard of if else?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question