Q
Q
Qwestyuio4272022-02-19 11:59:03
Bots
Qwestyuio427, 2022-02-19 11:59:03

Dividing a message into parts?

I want to make a change nickname command, but I don't know how to separate the change nickname command from the new nickname? I only know message.text.split()[]. telebot. example:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Dedinets, 2022-02-20
@donko1

So through your skills and execute
For example, the user posted /change_nick old_nick new_nick

def some_name(message):
 words = message.text.split()
 words.remove('/change_nick')
 # Соединяемся с базой но для простоты примера давайте представим что сохраняли это в словарик
 if nick_names[message.from_user.id] == words[0]:
  nick_names[message.from_user.id] = words[-1] # nick_names - хэш-таблица в которую мы сохраняли никнеймы в формате {id пользователя:его ник}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question