简体   繁体   English

试图让机器人使用 pytelegrambotapi 发送照片,但我不断收到 filenotfounderror

[英]trying to get a bot to send a photo using pytelegrambotapi but i keep getting the filenotfounderror

so i'm just trying to make a telegram bot for my friends birthday that's coming up soon and i am a super beginner at python and coding, know my basics here and there so please be nice.所以我只是想为即将到来的朋友生日制作一个电报机器人,我是 python 和编码的超级初学者,在这里和那里了解我的基础知识,所以请善待。 i'm using pytelegrambotapi and replit to code my bot, basically, i want the bot to send some images after a command has been triggered right.我正在使用 pytelegrambotapi 和 repli 对我的机器人进行编码,基本上,我希望机器人在正确触发命令后发送一些图像。 and i'm seriously copying the code for the image path correctly but somehow this error keeps popping up.我正在认真地正确复制图像路径的代码,但不知何故,这个错误不断弹出。 help!帮助!

photo1 = open(r"C:\Users\User\Desktop\bday\IMG_2201.PNG", 'rb')
@bot.message_handler(commands=['photo'])
def msg4(message):
  bot.send_photo(message.chat.id, photo1)

my code on replit and the error我的 repli 代码和错误

what i think im supposed to code for my bot to send an image我认为我应该为我的机器人编写代码以发送图像

There's the problem with your path python support //您的路径存在问题 python 支持//

Change you path to this C://Users//User//Desktop//bday//IMG_2201.PNG将路径更改为此C://Users//User//Desktop//bday//IMG_2201.PNG

if you give the correct path then this code will work for you如果您提供正确的路径,那么此代码将为您工作

photo1 = open("C://Users//User//Desktop//bday//IMG_2201.PNG", 'rb')
@bot.message_handler(commands=['photo'])
def msg4(message):
  bot.send_photo(message.chat.id, photo1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 pyTelegramBotAPI 在电报机器人中获取照片 - Get photo in telegram bot through pyTelegramBotAPI 如何使用 pyTelegramBotAPI 将文档发送到 Telegram Bot - How to send a document to a Telegram Bot using pyTelegramBotAPI 试图让 discord.py 机器人每 12 小时发送一次嵌入消息,但一直缺少参数“ctx” - Trying to get discord.py bot to send embeded message every 12 hours, but keep getting missing parameter 'ctx' 如何使用 pytelegrambotapi 安排电报机器人发送消息 - How to schedule telegraom bot send message with pytelegrambotapi 如何使用 pyTelegramBotAPI 获取照片? - How to get photos using pyTelegramBotAPI? 如何让机器人发送消息而不通过 PYTelegramBotAPI 向其发送消息 - How to make a bot send messages without sending it a message via PYTelegramBotAPI 我正在尝试使用 BeautifulSoup 获取此网站的标题,但我一直收到 TypeError,我该如何解决? - I'm trying to get the title for this website using BeautifulSoup but I keep getting a TypeError, how do I fix this? 我无法在 pyTelegramBotAPI 中发送文档 - I can't send documents in pyTelegramBotAPI 尝试编码 Twitter Bot 得到“FileNotFoundError: [Errno 2] No such file or directory: 'FILE_NAME'” - Trying to code Twitter Bot Getting “FileNotFoundError: [Errno 2] No such file or directory: 'FILE_NAME'” 无法使用 pytelegrambotapi 向 Telegram 频道发送消息 - Unable to send a message to a Telegram channel using pytelegrambotapi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM