I am completely new to python and trying to let my bot send a picture to a supergroup every day at the same time.
The problem is that just nothing happens.
Chat ID, bot token and URL are correct.
The bot is administrator in the group.
Using
https://api.telegram.org/botxxx/sendPhoto?chat_id=-xxx&photo=https://xxx
the bot sends the picture.
What is the mistake in the python script?
My second question is: How can I let the bot send another picture from another URL in the same script?
import requests
import telegram
import time
from datetime import datetime
bot_token = 'botxxx'
chat_id = '-xxx'
image_url = 'https://xxx'
def send_image():
bot = telegram.Bot(token=bot_token)
try:
bot.send_photo(chat_id=chat_id, photo=image_url)
print("Successfully sent!")
except Exception as e:
print("Error sending:", e)
def is_8pm():
now = datetime.now()
return now.hour == 20 and now.minute == 0 and now.second == 0
def main():
while True:
if is_8pm():
send_image()
time.sleep(60)
if __name__ == "__main__":
main()
user24531467 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.