Answer the question
In order to leave comments, you need to log in
How to make a Telegram bot (File Transfer)?
Earlier I asked a question about such a bot (apparently deleted). In general, my task was to make a bot that would throw some kind of file (txt.), Or rather its data, during the N-number of intervals.
Here is the code
import telebot
from telebot import types
bot = telebot.TeleBot('ВАШ ТОКЕН')
def main():
markup = types.ReplyKeyboardMarkup(True)
key1 = types.KeyboardButton('Статус Взлома')
markup.add(key1)
return markup
@bot.message_handler(commands=['Статус Взлома'])
def start(message):
bot.send_message(message.chat.id, 'Привет', reply_markup=main())
@bot.message_handler(content_types=['text'])
def cont(message):
with open('example.txt') as misc:
f = open('example.txt', 'rb')
bot.send_document(message.chat.id, f)
bot.polling()
Свою задачу выполняет, но когда даешь команду(нажимаешь кнопку).
Как сделать чтобы он отправлял файл сам? Без команды
Answer the question
In order to leave comments, you need to log in
you can track changes in a file using the watchdog module:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import time
class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
print('Файл {} изменился'.format(event.src_path))
observer = Observer()
observer.schedule(MyHandler(), path="example.txt", recursive=False)
observer.start()
while True:
time.sleep(1)
Ahem. Just take it out for pulling and send a message separately
chat_id = 746698178 # сюда чат айди
f = open('example.txt', 'rb')
bot.send_document(chat_id, f)
@bot.message_handler(content_types=['text'])
def mess(message):
bot.send_message(message.chat.id, message.chat.id) # Бот на текстовое сообщение вернет твой чат айди
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question