如何从Telebot上的本地存储中发送媒体专辑?
我正在尝试制作一个电报机器人,该机器人从本地存储中发送媒体,我遇到了这个错误。
另外,如果其中有10个项目的列表,并且您尝试发送,因为专辑会自动将它们分离到其他专辑中以发送它吗?
对电报API的请求不成功。错误代码:400。描述:不良请求:错误的HTTP URL指定
import telebot
import glob
import os
from telebot.types import InputMediaPhoto, InputMediaVideo
bot = telebot.TeleBot("")
@bot.message_handler(commands=['test'])
def test(message):
id = message.chat.id
path = "./vid/*.mp4"
vid_media = []
#i might remove this i think this is not needed
for files in glob.glob(path):
print(files)
for i in os.listdir("./vid/"):
vid_media.append(InputMediaVideo(i))
bot.send_message(id, "Sending videos...")
for i in vid_media:
with open(i, 'rb') as f:
bot.send_media_group(id, vid_media)
bot.polling()
I'm trying to make a telegram bot that sends media from local storage and i got this error.
Also if there is a list with over 10 items on it and you try to send as a album does telegram automatically seperates them to different album to send it?
A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: wrong HTTP URL specified
import telebot
import glob
import os
from telebot.types import InputMediaPhoto, InputMediaVideo
bot = telebot.TeleBot("")
@bot.message_handler(commands=['test'])
def test(message):
id = message.chat.id
path = "./vid/*.mp4"
vid_media = []
#i might remove this i think this is not needed
for files in glob.glob(path):
print(files)
for i in os.listdir("./vid/"):
vid_media.append(InputMediaVideo(i))
bot.send_message(id, "Sending videos...")
for i in vid_media:
with open(i, 'rb') as f:
bot.send_media_group(id, vid_media)
bot.polling()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不能直接使用到本地文件的路径。
您必须将内容发送为字节:
完整的工作代码:
编辑:
不同的模块可能具有不同的功能。
此代码使用模块
telebot
( pytelegrambotapi 路径但是似乎模块
电报
可以使用pathlib.path
在其 inputMediaVideo 。It can't use directly path to local file.
You have to send content as bytes:
Full working code:
EDIT:
Different modules may have different functionalities.
This code uses module
telebot
(pyTelegramBotAPI) and it can't use local pathbut it seems module
telegram
can usepathlib.Path
with local path in its InputMediaVideo.