Answer the question
In order to leave comments, you need to log in
How to record messages that the user sends to the bot in a notepad ??
The user sends messages in a personal message to the bot. The bot sees the messages and writes it to a notepad or outputs it to the console.
Answer the question
In order to leave comments, you need to log in
You put a handler to receive a message (how it depends on the library used), in it you already do print or output to a file.
For the python-telegram-bot package, this would be something like
from telegram.ext import MessageHandler, Filters
def on_message(update, context):
pass #тут делаешь что хочешь с update.message.text
message_handler = MessageHandler(Filters.text & (~Filters.command), on_message)
dispatcher.add_handler(message_handler)
from aiogram import Bot, Dispatcher, executor, types
from config import TOKEN
bot = Bot(TOKEN)
dp = Dispatcher(bot)
@dp.message_handler()
async def tex(message: types.Message):
await bot.send_message(message.chat.id, message.text)
with open('tee.txt', 'a+') as file_tee:
file_tee.write(f'{message.from_user.first_name} - {message.text}\n')
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)
with open('tee.txt', 'a+') as file_tee:
file_tee.write(f'{message.from_user.first_name} - {message.text}\n')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question