Build a Message Bomber Using Python in Just 6 Lines of Code
Tags: python, programming, computerscience, beginners
Published: 2021-02-11 11:30:28

Welcome to the  [Python Projects for Beginners Series](https://hashnode.com/series/python-projects-for-beginners-ckk31d9370h0vrus1blfl0a4y) 🙋🏻‍♂️

I'm [Sai Ashish](https://www.linkedin.com/in/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
```

*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
```
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](https://pyautogui.readthedocs.io/en/latest/). 
 
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](https://docs.python.org/3/library/time.html)📄 

## 3. Time to Code!

![The Insightful Coder: Time to Code](https://cdn.hashnode.com/res/hashnode/image/upload/v1611771833314/Uugrd3XOg.jpeg)

You can **access the exclusive theory** for this build [here](https://github.com/SaiAshish-Konchada/Python-Projects-for-Beginners/tree/main/Message%20Bomber)💣

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

```
# Importing the required libraries
import pyautogui, time
```

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)
```
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')
```

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')
```
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 🐍 <br>
**Step 2:** Open the app through which you want to spam 📱<br>
**Step 3:** Run the message bomber program 🏃🏻‍♂️<br>
**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 ⏳<br>
**Step 5:** Step back, grab some popcorn, and watch your bot unleash the power 🍿<br>

The final source code looks like this:

![Code for Message Bomber Using File in Python](https://cdn.hashnode.com/res/hashnode/image/upload/v1612010360032/aCXejtJLh.png)

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](https://cdn.hashnode.com/res/hashnode/image/upload/v1612011172028/Xz8GvFjnF.png)

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](https://github.com/SaiAshish-Konchada/Python-Projects-for-Beginners)  😍 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](https://github.com/SaiAshish-Konchada/Python-Projects-for-Beginners/tree/main/Message%20Bomber). 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](https://theinsightfulcoder.com/) :

-  Interested in Building Your Own Artificial Intelligence Projects using Python?: Check out the [Python AI Series](https://hashnode.com/series/python-ai-series-ckkft33ux016dwjs11xlqbz4v)🧠

- Wanna Discover Some Valuable Tech-Hacks 🛠?: Check out the [Tech-Hacks for Everybody Series](https://hashnode.com/series/tech-hacks-for-everybody-ckk3juqc10ihoqps16q0geabj)😎

- Wanna Interact With Me 🙋🏻‍♂️? Connect With Me on Your Favourite Platform [Here](https://theinsightfulcoder.com/contact-me)  🤝🏻

- Find and Download All My Project Source Codes at My [Github Repository](https://github.com/SaiAshish-Konchada)  🎁