1

I have a little spam bot for discord.

import pyautogui

from time  import sleep 

time = 0 
while time != 10:
        time += 1
        sleep(1)
        print ("Get Ready" + str (time) )

def spam(msg, maxMsg):
        count = 0
        while count != maxMsg:
                count += 1
                print("send message: " + str(count ))
                pyautogui.write(msg)
                pyautogui.press("enter")
                if count == 5 or count == 10 or count == 15:
                        sleep(8)

 spam('Test', 15)

My problem is in if count the cap here would be 15 but i want it to be 500 without writing or count == 20 or count == 25 until 500 is there a way to say sleep on every multiple of 5?

user14678216
  • 2,886
  • 2
  • 16
  • 37

1 Answers1

2
import pyautogui

from time  import sleep 

time = 0 
while time != 10:
        time += 1
        sleep(1)
        print ("Get Ready" + str (time) )

def spam(msg, maxMsg):
        count = 0
        while count != maxMsg:
                count += 1
                print("send message: " + str(count ))
                pyautogui.write(msg)
                pyautogui.press("enter")
                if count % 5 == 0 and count <= 500
                        sleep(8)

 spam('Test', 15)

Use the modulo operator: it returns the remainder of the division between two numbers. That is: if A % B = C (A, B, C are integers) then there is an integer K such that A = B * K + C. In your specific question, if count % 5 = 0, then count is a multiple of 5 because there is an integer K such that A = 5 * K + 0 = 5 * K. This shows that A must be a multiple of 5.

And I forgot: you need to check if count is less than or equal to 500, of course.

LuxGiammi
  • 631
  • 6
  • 20