pyTelegramBotAPI cannot use other libraries as I have already done many functions for this bot. I need to add a function to the bot with which it will be possible to save the text from the user and + then change this text, it is best to save all this in .txt. Please help if you can)
Answer # 1
In what sense should the text be saved? To get some text from the user use @ bot.message_handler or bot.register_next_step_handler, to change the message use bot.edit_message_text
If you just want to receive his message and record, then use @ bot.message_handler:
@ bot.message_handler (content_types= ["text"]) def write (message): text= message.text f= open ("writes.txt", "a") f.write (text) f.close ()
Answer # 2
It's very simple. When the user writes the command /write There was a storm yesterday, you need to separate the command and its arguments.
data= message.text data= data.replace ("/write", "")
Voila, you have all the rest of the text.
data= message.text data= data.split ("") data= data [1:]
Voila and you already have all the data, but in the form of a list. This is generally done by built-in library functions. I did not write on your library, but I used it in a more powerful aiogram. There is a built-in parameter args. You do not, and all arguments entered with the command are accepted. You can google if your library has it.
- python : Can't send YooKassa payment window to Telegram
- python : Is it possible to connect payment to an individual? TELEGRAM BOT
- python : Error in telebot bot
- python : Can telebot code be changed to aiogram?
- python : Embedding a link in a telegram bot message without a popup when displaying
- python : The bot does not display the previously specified value
- python : The code is knocking out an error
- python : Parser comments from a post in telegram
- python : Is it possible to parse TG channels?
- python : Error sending message with Markdown formatting