The Wayback Machine - https://web.archive.org/web/20250118091329/https://www.geeksforgeeks.org/spam-bot-using-pyautogui/
Open In App

Spam bot using PyAutoGUI

Last Updated : 02 Feb, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

PyAutoGUI is a Python module that helps us automate the key presses and mouse clicks programmatically. In this article we will learn to develop a spam bot using PyAutoGUI.

Spamming – Refers to sending unsolicited messages to large number of systems over the internet. 

This mini-project can be used for many real-life applications like:

  • Remind your friends or relatives to do a particular task after every particular time interval
  • Can be used for advertisement purpose

In this article we will show the working of spam bot on telegram, but the code can also work for WhatsApp, Instagram etc. i.e. anywhere we find a text field it will work the same way.

Approach

  • Import module
  • Add delay of 2 second in the execution of the program
  • Create mechanism to generate text messages. typewrite() function of pyautogui helps to write the text and sleep function helps us specify the particular time interval (in seconds) after which the next instruction has to be executed. datetime.datetime.now() function helps the user keep a track of when the message was sent.

Syntax:

typewriter(“<message>”)

  • Execute code

Follow these simple steps to develop a spam bot using python:

Example:

Python3




import pyautogui, time, datetime
  
time.sleep(2)
  
while True:
    
    # to display the time at which the message is sent 
    print(datetime.datetime.now())
    pyautogui.typewrite("Reminder: Drink water!") 
    pyautogui.press("enter")
    time.sleep(31)
  
    print(datetime.datetime.now())
  
    pyautogui.typewrite("Reminder: Take medicine!")
    pyautogui.press("enter")
    time.sleep(31)
  
    print(datetime.datetime.now())
  
    pyautogui.typewrite("Reminder: Take the dog for a walk!")
    pyautogui.press("enter")
    time.sleep(31)
  
    print(datetime.datetime.now())
  
    pyautogui.typewrite("Reminder: Drink water!")
    pyautogui.press("enter")
    time.sleep(31)
  
    print(datetime.datetime.now())
  
    pyautogui.typewrite("Reminder: Drink water!")
    pyautogui.press("enter")
    time.sleep(31)


Output:  

Date and time at which the message was sent 


Enhance your coding skills with DSA Python, a comprehensive course focused on Data Structures and Algorithms using Python. Over 90 days, you'll explore essential algorithms, learn how to solve complex problems, and sharpen your Python programming skills. This course is perfect for anyone looking to level up their coding abilities and get ready for top tech interviews.
Join the Three 90 Challenge and commit to completing 90% of the course in 90 days to earn a 90% refund. It’s the perfect way to stay focused, track your progress, and reap the rewards of your hard work. Take the challenge and become a DSA expert in Python today


Next Article
Practice Tags :

Similar Reads

three90RightbarBannerImg