I am writing a Python script -a bot that will change my nickname using the buttons from the telegram keyboard There was a problem -the bot changes its nickname only when called under with, and I cannot insert bot handlers under it -then the bot will not accept them. How can this problem be solved? The code:

from pyrogram import Client
from pyrogram.raw import functions
import time
import json
from datetime import datetime
import telebot
telebot import types
bot= telebot.TeleBot('token')
print("bot component setup finished")
config= json.loads(open('config.json').read())
with Client("app", config['API_ID'], config['API_HASH']) as app:
    #the function of changing nickname itself, it works under with
        print('CHANGE NICK TO:', nick)
        except Exception as e:
        print("nick changed")
def start(message):
    print("message arrived")
    if message.text== 'bj':
      keyboard= types.InlineKeyboardMarkup()
      buttons= [
            types.InlineKeyboardButton(text='Working', callback_data='working'),
            types.InlineKeyboardButton(text='Sleeping', callback_data='sleeping'),
            types.InlineKeyboardButton(text='Default', callback_data='default')
      for b in buttons:
        bot.send_message(message.from_user.id, text="?", reply_markup=keyboard)
        bot.send_message(message.from_user.id, '?');
@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
    ChangeNick(config.get("NAMES").get(call.data)+" []") #change nickname by button
bot.polling(none_stop=True, interval=0)

and if the construction with to thrust under def?

Anatoly Kritskiy2022-01-26 10:09:14

@AnatolyKritskiy same thing happens

likel0vsky2022-01-26 10:09:14

What does "the bot won't accept them" mean?

oleksandrigo2022-01-25 11:13:03

@oleksandrigo will not process messages, buttons on this function

likel0vsky2022-01-25 13:20:55