N
N
Nikolai Ostrovsky2021-03-16 01:06:18
Bots
Nikolai Ostrovsky, 2021-03-16 01:06:18

How to make Telebot check for a user and only accept him?

Hello, how can I implement a check so that a message is sent only after checking a specific user? For example, the bot should only respond to my message.
Tried checking bot.get_chat_member(message.chat.id, "my id"), when writing it outputs creator, but when trying to make a condition if if ... == "creator" matches, executes subsequent actions from all users.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2021-03-16
@KotoFeyic

import telebot

token = 'token'

bot = telebot.TeleBot(token)

ADMIN = 121495485 # Цифры заменить на свой id

@bot.message_handler(content_types=['text'])
def repeat_all_message(message):
  print(message.chat.id)
  if message.chat.id == ADMIN:
    bot.send_message(message.chat.id,'Ты админ')
  else:
    bot.send_message(message.chat.id,'Ты не админ')

if __name__ == '__main__':
    bot.polling(none_stop=True)

S
Stefan, 2021-03-16
@MEDIOFF

when requesting id, id should be returned, not 'creator', see for yourself, there is an error in the code.
You are most likely not requesting the id correctly, I don’t know about the body of the bot, but in aiogram it is message.from_user.id.
bot.get_chat_member - I don't think this is needed, just write \
if message.chat.id == <Мой id>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question