G
G
ganyamede2021-06-27 21:47:30
Python
ganyamede, 2021-06-27 21:47:30

How to make a variable in Telebot?

import telebot
from telebot import types
bot = telebot.TeleBot("token")

@bot.message_handler(commands=['nick'])
def st(message):
    da = bot.send_message(message.chat.id, "Ку, введи свое имя:")
    bot.register_next_step_handler(da, net)

def net(message):
    bot.send_message(message.chat.id, f'твое имя: {message.text}')

print('on')
if name == 'main':
  bot.polling(none_stop=True)



как сделать что бы когда от def st перешло на def net по команде, 
допустим ввели /nick, бот отвечает:
Ку, введи свое имя: 
Я ввел допустим Иван
и после что бы бот сказал имя ваше нужно ввести команду допустим /name 
твое имя: Иван

если что вот так не работает

@bot.message_handler(commands=['name'])
def net(message):
    bot.send_message(message.chat.id, f'твое имя: {message.text}')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-06-27
@twistfire92

Somehow it is not entirely clear what you want to get as a result. Read for yourself what you wrote, correct it to make it clearer (for example, by placing commas) and show what you are getting now.
If I understood the question correctly (which I doubt), you need to remember the name entered by the user so that when you use the /name command, the bot sends the username.
In this case, you need to use a database. There you will save the correspondence of the user IDs and their names that they enter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question