I am currently struggling with creating a spamming bot for several groups and the only way I found is the following:
import pyautogui
import time
msg = input("Enter the message: ")
n = input("How many times ?: ")
print ("t minus")
count = 5
while(count != 0):
print(count)
time.sleep(1)
count -= 1
print("Fire in the hole!!!")
for i in range(0,int(n)):
pyautogui.typewrite(msg)
But in this case its only allowing me to put a single line message. My complete desire is to read from a file, so I can prepare the file script to execute it (read from it).
But if this is not achievable can you advise me how to modify this code at least to allow me to add new line not send a single one (as from the case above).
2
Answers
To get the variable
msg
to include a new line, you can type /n. More info here.You can go to a next line in Telegram using shift+enter. To get pyautogui to type this you can use:
You will probably need to create a function that separates the
msg
into individual lines and then executes the above pyautogui code between each line.I will also point out though, that you may want to take a different approach than pyautogui. Telegram has an API that you can you to automatically send messages, and it would probably be much easier to use that.
If you want to read text from a file and send that, you could do something like:
If you have to use the user input function, this answer suggests redirecting your standard input to a file and reading from a file, like so:
You may not be able to use the context manager with input (the context manager handles opening and closing automatically, but you can’t keep working on a closed file), in which case it would look like: