Advertisement
Iammrjude

message.chat.id not working in Callback_query_handler

May 12th, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. @bot.message_handler(commands=['start'])
  2. def start_message(message):
  3.     global user #tried making user,fn and Lname to be global variables
  4.     global fn
  5.     global Lname
  6.     fn=message.chat.first_name
  7.     Lname=message.chat.last_name
  8.     user=str(fn)+' '+str(Lname)
  9.     markup = telebot.types.InlineKeyboardMarkup()
  10.     acct=telebot.types.InlineKeyboardButton(text='👤 Account', callback_data=1)
  11.     ref=telebot.types.InlineKeyboardButton(text='👥 Referrals', callback_data=2)
  12.     stats=telebot.types.InlineKeyboardButton(text='📈 Stats', callback_data=3)
  13.     power=telebot.types.InlineKeyboardButton(text=' ⚡️ Buy Power',callback_data=4)
  14.     payout=telebot.types.InlineKeyboardButton(text='💲 Payouts', callback_data=5)
  15.     withdraw=telebot.types.InlineKeyboardButton(text='💵 Withdraw', callback_data=6)
  16.     markup.row(acct)
  17.     markup.row(ref,stats)
  18.     markup.row(power,payout,withdraw)
  19.     bot.send_message(message.chat.id, text="WELCOME"+user, reply_markup=markup) # user working here in the message handler but won't work in callback_query_handler
  20.  
  21. @bot.callback_query_handler(func=lambda call: True)
  22. def query_handler(call):
  23.     user=str(message.chat.first_name)+' '+str(message.chat.last_name)
  24.     markup = telebot.types.InlineKeyboardMarkup()
  25.     acct=telebot.types.InlineKeyboardButton(text='👤 Account', callback_data=1)
  26.     ref=telebot.types.InlineKeyboardButton(text='👥 Referrals', callback_data=2)
  27.     stats=telebot.types.InlineKeyboardButton(text='📈 Stats', callback_data=3)
  28.     power=telebot.types.InlineKeyboardButton(text=' ⚡️ Buy Power',callback_data=4)
  29.     payout=telebot.types.InlineKeyboardButton(text='💲 Payouts', callback_data=5)
  30.     withdraw=telebot.types.InlineKeyboardButton(text='💵 Withdraw', callback_data=6)
  31.     wallet=telebot.types.InlineKeyboardButton(text='🏦 Wallet', callback_data=7)
  32.     email=telebot.types.InlineKeyboardButton(text='📧 Email', callback_data=8)
  33.     bot.answer_callback_query(callback_query_id=call.id)
  34.     if call.data == '1':
  35.         markup.row(acct)
  36.         markup.row(ref,stats)
  37.         markup.row(wallet,email)
  38.         markup.row(power,payout,withdraw)
  39.         msg='👤 GENERAL INFORMATION\n\n◽ User: '+user+'\n◽ Balance: ' #so I wanted the bot to print the information of the bot user (First_name and last_name) but it's not working. It breaks the code and says user not defined.
  40.         bot.send_message(call.message.chat.id,msg,reply_markup=markup)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement