B
B
bakin20042019-09-26 20:58:31
Python
bakin2004, 2019-09-26 20:58:31

An error in the code when trying to restrict access to the bot?

Help with solving the error. I decided to restrict access to the telegram bot like this:

import telebot

bot = telebot.TeleBot('мой ключ бота')

@bot.message_handler(commands=['start'])

def checkuserCommand(bot,update):
    if update.message.from_user.id == "мой айди телеграмма":
        if update.message.text == "/start":
            def start_message(message):
                bot.send_message(message.chat.id, 'Привет!')

bot.polling(none_stop=True, interval=0)

But gives an error:
2019-09-26 22:51:32,244 (util.py:65 WorkerThread1) ERROR - TeleBot: "TypeError occurred, args=("checkuserCommand() missing 1 required positional argument: 'update'",)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jack Surfer, 2019-09-26
@bakin2004

Keep the correct code!

import telebot

bot = telebot.TeleBot('мой ключ бота')


@bot.message_handler(commands=['start'])
def start(message):
    if message.from_user.id == "мой айди телеграмма":
        bot.send_message(message.chat.id, 'Привет!')


bot.polling(none_stop=True, interval=0)

D
Dmitry Shitskov, 2019-09-26
@Zarom

Why do you have bot in function parameters when message should be there? And what do you have for update in the parameters? The function has only 1 argument according to the documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question