简体   繁体   中英

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. 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. 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

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

There's the problem with your path python support //

Change you path to this 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM