【问题标题】:trying to get a bot to send a photo using pytelegrambotapi but i keep getting the filenotfounderror试图让机器人使用 pytelegrambotapi 发送照片,但我不断收到 filenotfounderror
【发布时间】:2022-01-16 03:19:36
【问题描述】:

所以,我是编码和 Python 的超级初学者,正在尝试为我朋友即将到来的生日制作一个电报机器人。我在这里和那里都知道我的基础知识,所以请友善!我正在使用 pyTelegramBotAPIReplit。基本上,我希望机器人在正确触发命令后发送一些图像。我正在正确复制图像路径的代码,但不知何故此错误不断弹出。救命!

    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

what i think im supposed to code for my bot to send an image

【问题讨论】:

    标签: python telegram-bot py-telegram-bot-api


    【解决方案1】:

    你的路径python支持//有问题

    改变你的路径 C://Users//User//Desktop//bday//IMG_2201.PNG

    如果您提供正确的路径,那么此代码将为您工作

    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)
    

    【讨论】:

      猜你喜欢
      • 2022-09-28
      • 2016-07-31
      • 2017-08-05
      • 2016-10-17
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 2010-10-25
      相关资源
      最近更新 更多