N
N
neuro4live2021-03-27 23:14:00
Python
neuro4live, 2021-03-27 23:14:00

How to send files to a telegram channel using a bot?

Hello. I have a telegram bot that creates entries in the channel: publishes a video (more than 50 mb) and screenshots for it. Video uploaded in advance and sent to the bot. I have a script that can send the file_id of this video, respectively, using this id, you can send the file further. The script that sends the video to the channel consists of two parts: The first one allows you to get the id file. The second one, which already creates an entry in the channel. With the help of the return function, I am trying to pass the id file to the second part of the script. pytelegrambotAPI libraries Here is the code:

import telebot
from telebot.types import InputMediaPhoto, InputMediaVideo

bot = telebot.TeleBot('токкен бота')


@bot.message_handler(content_types=['video'])
def command_handle_video(message):
  bot.send_message(message.chat.id, message.video.file_id)
  return(bot.send_message)



c=chat_id = 'айди канала'
d = open('/home/roman/Изображения/123.png', 'rb')
f = command_handle_video(message)


bot.send_media_group(c,
                    [InputMediaPhoto(d, caption='описание видео'),
                     InputMediaVideo(f)])


When I run the script I get this error:
Traceback (most recent call last):
File "/home/roman/PycharmProjects/pythonProject8/main.py", line 18, in
f = command_handle_video(message)
NameError: name 'message ' is not defined

Id file is not answered. I have a script that can send an ID file and write it to a text file, then it can be read and sent from there, but I want to do without saving to a file, so I decided to use the return functions. Please tell me where is the error. Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-03-27
@SoreMix

Why not

@bot.message_handler(content_types=['video'])
def command_handle_video(message):
  bot.send_message(message.chat.id, message.video.file_id)
  d = open('/home/roman/Изображения/123.png', 'rb')
  bot.send_media_group('айди канала',
                    [InputMediaPhoto(d, caption='описание видео'),
                     InputMediaVideo(message.video.file_id)])

?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question