Answer the question
In order to leave comments, you need to log in
Why does telebot function fire twice?
def check(message):
if client.get_chat_member(channel_chat_id, message.chat.id).status in need_status:
return True
else:
client.send_message(message.chat.id, subscribe_error_msg)
return False
@client.message_handler(commands = ['start'], func=check)
def hello(message):
with sqlite3.connect("users.db") as con:
cur = con.cursor()
info = cur.execute('SELECT * FROM users WHERE userid=?', (int(message.chat.id), ))
if info.fetchone() is None:
user_info = (int(message.chat.id), message.from_user.first_name, message.from_user.last_name, undefined_status)
cur.execute(f"""INSERT INTO users VALUES(?, ?, ?, ?);""", user_info)
con.commit()
sti = open('static/welcome.webp', 'rb')
client.send_sticker(message.chat.id, sti)
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton(register)
markup.add(item1)
client.send_message(message.chat.id, hello_message.format(message.from_user, client.get_me()), parse_mode='html', reply_markup=markup)
Answer the question
In order to leave comments, you need to log in
Apparently, the situation is as follows:
you have several handlers, each of which checks for the presence of a user in the chat.
@client.message_handler(commands = ['start'], func=check)
@client.message_handler(content_type= ['text'], func=check)
def check(message):
if client.get_chat_member(channel_chat_id, message.chat.id).status in need_status:
return False
else:
return True
@client.message_handler(content_types=['text'], func=check)
def access_denied(message):
client.send_message(message.chat.id, subscribe_error_msg)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question