T
T
typical_user102020-08-21 23:15:32
Python
typical_user10, 2020-08-21 23:15:32

How to make access by id?

Tell me please. How can I implement access to a specific command by user id?

Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
U
UberPool, 2020-08-22
@typical_user10

Here's an example from the documentation:

def check_if_it_is_me(ctx):
    return ctx.message.author.id == 85309593344815104 #id человека 

@bot.command()
@commands.check(check_if_it_is_me) #проверка от того ли человека пришла команда
async def only_for_me(ctx):
    #делаете что-то

What you need.
You can also check if a person has a role to execute a command:
@bot.command()
@commands.has_any_role('Moder','admin', 492212595072434186) 
async def command(ctx):
    #и делаете что-то

T
Ternick, 2020-08-21
@Ternick

It depends on how and which teams you want to split.
You can make two types of user. An administrator and a regular user, and accordingly make a condition, if the user is an administrator, allow him to use all commands, otherwise allow him to use a limited range of commands.
To do this, you need to save all administrators to yourself and, at each request for a command, see if the user can execute it. Roughly the same can be done with several groups of users.

A
AruxGame, 2020-08-22
@AruxGame

I don’t know how to do this in DISCORD, I write bots on telegrams, but try to remake it under DISCORD!
Here is the code:

@bot.message_handler(commands=['admins'])
def admin(message):
  if message.chat.id == 123456789: # Вместо 123456789 напиши свой ID, только не ставь кавычки!
    bot.send_message(message.chat.id, 'Вы в Админ-Панели!')

  else:
    bot.send_message(message.chat.id, 'Нет ДОСТУПА Обратитесь к Администрации!')

Instead of 123456789 write your ID, just do not put quotes!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question