DEV Community

Sai Ashish
Sai Ashish

Posted on • Updated on • Originally published at theinsightfulcoder.com

Build a Message Bomber Using Python in Just 6 Lines of Code

Welcome to the Python Projects for Beginners Series ๐Ÿ™‹๐Ÿปโ€โ™‚๏ธ

I'm Sai Ashish and today, I'm going to show you how to spam your friends by building a message bomber using just 6 lines of code๐Ÿ˜

How psyched are you for this build? Let's get started ๐Ÿš€

What are we going to learn today?

1. The PyAutoGUI module
2. The Time module
3. Basics of Python: Iterative Statement
4. Implementation of Message Bomber Using Python with detailed explanation
Enter fullscreen mode Exit fullscreen mode

P.S. Use this project wisely for fun purposes only. Don't go on spamming people and get blocked ๐Ÿ˜†

For this build, we are going to use the PyAutoGUI module of Python.

1. What is PyAutoGUI?

PyAutoGUI is a python module that lets you control your mouse and keyboard using a program.

To install PyAutoGUI in your system, open your terminal and run:

pip install pyautogui
Enter fullscreen mode Exit fullscreen mode

PyAutoGUI has several features including:

  • Moving the mouse and clicking or typing in the windows of other applications.
  • Sending keystrokes to applications (for example, to fill out forms).
  • Take screenshots, and given an image (for example, of a button or checkbox), find it on the screen.
  • Locate an applicationโ€™s window, and move, resize, maximize, minimize, or close it (Windows-only, currently)
  • Display message boxes for user interaction while your GUI automation script runs.

Source: Official documentation of PyAutoGUI.

PyAutoGUI also lets you automate your everyday tasks and can play games, login into emails, and more.

2. What is the Time Module?

The time module provides various time-related functions. We use it to retrieve the system time and display it on the screen. You can access the official documentation form here๐Ÿ“„

3. Time to Code!

The Insightful Coder: Time to Code

You can access the exclusive theory for this build here๐Ÿ’ฃ

The first step is to import the PyAutoGUI and the Time module.

# Importing the required libraries
import pyautogui, time
Enter fullscreen mode Exit fullscreen mode

Next, we need to set the program to sleep for 10 seconds. you'll get to know the reason at the end of the implementation.

# Delay to switch windows
time.sleep(10)
Enter fullscreen mode Exit fullscreen mode

I plan to spam my friend with the script of the Green Lantern movie ๐Ÿฎ Sorry, Ryan ๐Ÿ˜
I already have downloaded the script of the movie. All I have to do is to load it into my environment.

Make sure to provide the full path of the file with an extension, if the file isn't located at the same location as the program. Otherwise, the name of the file with the extension is enough.

# Load the file contents in read mode
file = open("Green-Lantern-Movie-Script.txt", 'r')
Enter fullscreen mode Exit fullscreen mode

You've loaded the word bullets. Your program gun is on point. All that's left to do is fire it ๐Ÿ”ฅ

# loop to spam
for word in file:
      # Fetch and type each word from the file
      pyautogui.write(word)
      # Press enter to send the message  
      pyautogui.press('enter')
Enter fullscreen mode Exit fullscreen mode

Here, we set a loop to iterate over each word in the file. We use write() function to type the keys and then use the press() function to click enter and send the message. Therefore, our message bomber takes each word from the file and spams right into where we want to.

Your program is ready. Let me show you how it's done ๐Ÿ˜Ž

Step 1: Open your Python environment ๐Ÿ

Step 2: Open the app through which you want to spam ๐Ÿ“ฑ

Step 3: Run the message bomber program ๐Ÿƒ๐Ÿปโ€โ™‚๏ธ

Step 4: Quickly switch the window from the python environment to the application and point the cursor on the user's chat area. We chose the delay of 10 seconds to perform this action in the meantime โณ

Step 5: Step back, grab some popcorn, and watch your bot unleash the power ๐Ÿฟ

The final source code looks like this:

Code for Message Bomber Using File in Python

If you do not want to use a file, you can just eliminate the file statement and use

pyautogui.write("Random Annoying Spam Words")

instead of pyautogui.write(word) while keeping a count loop.

Code for Message Bomber Using Message in  Python

We did it ๐Ÿฅณ We have made our own Message Bomber using Python in just 6 lines of code! How amazing is that? As a gift for staying till now, you get access to my Python For Beginners Series Repository ๐Ÿ˜ This repository contains all the source code you'd need to get started as a Python Developer ๐Ÿ.

You can also download the source code to this project here. Do hit the twinkle star, if this article provided value to you ๐Ÿ”ฅ

And while you're at it, consider giving this blog the maximum love you can and I promise to give you such value bombs every week ๐Ÿ’ฃ Until then, take care ๐Ÿ™‹๐Ÿปโ€โ™‚๏ธ

Bonus Insights by The Insightful Coder :

  • Interested in Building Your Own Artificial Intelligence Projects using Python?: Check out the Python AI Series๐Ÿง 

  • Wanna Discover Some Valuable Tech-Hacks ๐Ÿ› ?: Check out the Tech-Hacks for Everybody Series๐Ÿ˜Ž

  • Wanna Interact With Me ๐Ÿ™‹๐Ÿปโ€โ™‚๏ธ? Connect With Me on Your Favourite Platform Here ๐Ÿค๐Ÿป

  • Find and Download All My Project Source Codes at My Github Repository ๐ŸŽ

Top comments (0)