Home>

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:

print("o")
from pyrogram import Client
from pyrogram.raw import functions
import time
import json
from datetime import datetime
print("+")
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
    defChangeNick(nick):
        print('CHANGE NICK TO:', nick)
        try:
            app.update_profile(first_name="Pyrogram")
        except Exception as e:
            print(e)
        #app.send(functions.account.UpdateProfile(first_name="Test"))
        print("nick changed")
@bot.message_handler(content_types=['text'])
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:
        keyboard.add(b)
        bot.send_message(message.from_user.id, text="?", reply_markup=keyboard)
      else:
        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