Answer the question
In order to leave comments, you need to log in
Authorization in telegram bot?
Tell me how to make an authorization check by chat_id and priority on id-groups, for example 1-Admin (the Admin menu pops up)
2-User (a greeting pops up).
Answer the question
In order to leave comments, you need to log in
Here is the simplest code. Write the /admin command to the bot - and it will respond depending on the situation. For example, if user_id is in the database, and user_group_id = '1' - then the bot welcomes the admin, if user_group_id is not equal to '1', then the bot welcomes the user. If the user_id is not in the database at all, then it says that the user is not registered in the database.
import sqlite3
import telebot
token = 'ТОКЕН'
bot = telebot.TeleBot(token)
def getAccess(user_id):
with sqlite3.connect('users.db') as conn:
cursor = conn.cursor()
cursor.execute('SELECT user_group_id FROM users WHERE user_id=?',(user_id,))
result = cursor.fetchone()
return result
@bot.message_handler(commands=['admin'])
def repeat_all_message(message):
print(message.chat.id)
bot.send_message(message.chat.id,message.text)
access = getAccess(message.chat.id)
if access:
if access[0] == '1':
bot.send_message(message.chat.id,'Привет Admin!')
else:
bot.send_message(message.chat.id,'Привет User!')
else:
bot.send_message(message.chat.id,'Вы не зарегистрированны в системе!')
if __name__ == '__main__':
bot.polling(none_stop=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question