'Multiple actions within one while loop python

I need help with an experimental python bot that allows one to be afk and grind discord bots. (And I'm new to programming so please don't judge). Im trying to get all my def... into one variable but so all def... run at the same time.

    import pyautogui
    import time
    
    time.sleep(10)
    
    x = 0
    
    def a():
        pyautogui.typewrite(";sell")
        pyautogui.press("enter")
        pyautogui.typewrite("vf")
        pyautogui.press("enter")
        pyautogui.typewrite("t!fish")
        pyautogui.press("enter")
        time.sleep(5)
    
    def b():
        pyautogui.typewrite("owoh")
        pyautogui.press("enter")
        pyautogui.typewrite("owob")
        pyautogui.press("enter")
        time.sleep(15)
    
    def c():
        pyautogui.typewrite("pls beg")
        pyautogui.press("enter")
        pyautogui.typewrite("pls dig")
        pyautogui.press("enter")
        pyautogui.typewrite("pls fish")
        pyautogui.press("enter")
        pyautogui.typewrite("pls hunt")
        pyautogui.press("enter")
        time.sleep(35)
    
    def d():
        pyautogui.typewrite("owo pray")
        pyautogui.press("enter")
        pyautogui.typewrite(";fish")
        pyautogui.press("enter")
        pyautogui.typewrite("pls hunt")
        pyautogui.press("enter")
        time.sleep(300)
    
    def e():
        pyautogui.typewrite("pls work")
        pyautogui.press("enter")
        pyautogui.typewrite("$p")
        pyautogui.press("enter")
        time.sleep(4500)
    
    def main():
        a()
        b()
        c()
        d()
        e()
    
    while x < 10:
        main()
        x +=1

So I'm basically trying to get all run at once so that every 5 seconds it sends the 5s items but also starts writes the 15s and 35 etc. during the same time. As it is now it sends the 5s items waits 5 seconds and moves on the the 15s items.



Solution 1:[1]

Here's how this would work with the schedule module.

import pyautogui
import schedule
import time

def say(*words):
    for s in words:
        pyautogui.typewrite(s)
        pyautogui.press("enter")

def a():
    say(';sell','vf','t!fish')

def b():
    say('owoh', 'owob')

def c():
    say("pls beg", 'pls dig', 'pls fish', 'pls hunt')

def d():
    say('owo pray', ';fish', 'pls hunt')

def e():
    say('pls work', '$p')

def main():
    schedule.every(5).seconds.do(a)
    schedule.every(15).seconds.do(b)
    schedule.every(35).seconds.do(c)
    schedule.every(5).minutes.do(d)
    schedule.every(75).minutes.do(e)

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

main()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1