Answer the question
In order to leave comments, you need to log in
How can I send a file through the tg bot?
Please help with the bot, it should send documents from the array while having an interval (it already exists there, so no help is needed with this). Here is the code itself:
import telebot
from telebot import types
import time
bot = telebot.TeleBot('1624298351:AAEaXHWkRHp8L67cx7iMq4bB-zT98fesWw4')
documentList = [open('D:\\My files\\Desktop\\telegram\\price 16 April. xls', 'rb'),
open('D:\\My files\\Desktop\\telegram\\Price April 17 Jangi.xls', 'rb'),
open('D:\\My files\\Desktop \\telegram\\Drag Promotion Price Apr 19.xls', 'rb'),
open('D:\\My files\\Desktop\\telegram\\Price Apr 21 yangi.xls', 'rb')]
@ bot.
keyboard = types.InlineKeyboardMarkup(row_width=1)
begin_button = types.InlineKeyboardButton(text="Start", callback_data="test")
keyboard.add(begin_button)
bot.reply_to(message,
f'I send prices every day, {message. from_user.first_name} Click start to start '
f'submitting prices',
reply_markup=keyboard)
@bot.callback_query_handler(content_type=['document'], func=lambda call: True)
def callback_worker(callback):
for i in range(len(documentList)):
bot.send_document(callback.message.chat.id, documentList[i])
time.sleep(5)
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
I propose the following option. We will store only the directory in the array.
documentList = ['D:\\My files\\Desktop\\telegram\\прайс 16 апрель.xls',
'D:\\My files\\Desktop\\telegram\\прайс 17 апрель янги.xls',
'D:\\My files\\Desktop\\telegram\\Драг Промоущн прайс 19 апрель.xls',
'D:\\My files\\Desktop\\telegram\\прайс 21 апрель янги.xls']
@bot.callback_query_handler(func=lambda call: True)
def callback_worker(callback):
for row in documentList:
bot.send_document(callback.message.chat.id, open(row, 'rb'))
time.sleep(5)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question