i’m trying to execute my code at a certain time every day and it’s not working

Check out the documentation here for a good example of how this should work

Simple answer is your bot() is trying to recursively execute itself, but the only thing that happens when it runs itself is that it tells itself to run itself again in one day at 6:41…meanwhile no print() statement is executed because it doesn’t exist inside the bot() function.

Your code executes the print() statement once because it runs it immediately after defines bot().

You never call bot() in this code, so that function never actually does anything.

Easy solution is to put your desired functionality in your bot() function and then add it to the schedule like so:

import schedule
import time

def bot():
    print("ya")

schedule.every(1).day.at("6:41").do(bot)

while True:
    schedule.run_pending()
    time.sleep(1)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top