在一周中的确切日期和时间执行命令

Execute command at exact day of the week and time

我想在一周的每一天更改我的 Discord 机器人的状态,例如,在周五下午 5 点将状态更改为“正在播放”。

我已经准备好状态的东西,但我不知道如何让机器人在适当的时候改变它。

关于我该怎么做的任何想法?

您可以使用 cron 作业来执行此操作 在 Ubuntu 中,只需在文件底部写入 [​​=10=] 和 运行 脚本命令。

https://pypi.org/project/schedule/

例子

    import schedule
    import time
    
    def job():
        print("I'm working...")
    
    schedule.every(10).minutes.do(job)
    schedule.every(10).seconds.do(job)
    schedule.every().hour.do(job)
    schedule.every().day.at("10:30").do(job)

    schedule.every(5).to(10).minutes.do(job)
    schedule.every().monday.do(job)
    schedule.every().wednesday.at("13:15").do(job)
    schedule.every().minute.at(":17").do(job)
    
    while True:
        schedule.run_pending()
        time.sleep(1)