Create an Instagram bot that follows, likes, comments, and uploads images in 10 mins.

Create an Instagram bot that follows, likes, comments, and uploads images in 10 mins.

Having a bot do all the hard work while you figure out other things is fancy and pleasant today.

I will be working you through the process of creating a bot that likes other people’s post and comment, upload images for you, and follow people you want to follow.

Cool right?

Prerequisite

Code Editor — vscode Little knowledge of Python Instagram account You can find the code repo here

First, we need to create an Instagram account for our bot, so sign up on Instagram and open one.

1.png

After creating your Instagram account, keep your UserName in a notepad, as we will use it soon.

Open your Vscode and let us build our bot.

2.png

Create a new file and name the file with an extension of .py, which is the file format for python.

3.png Next, we open our terminal, if you are using Vscode which is suggested you use, you will find the terminal at the top menu bar and it will open a new interface below your code panel.

4.png

Once it is running, type python — version to see if you have python installed and if you get an error sign here or you do not have python installed, please go over here and download python.

5.png

If you have python installed already then run pip install instabot this will install the library we would need to build our bot.

from instabot import Bot
my_bot = Bot()

Our first line is to import from our library instabot a function called Bot this function will be very useful in our bot creation and so we create a variable of Bot()

my_bot.login(username=" ", password=" ")

Next, we log our bot into the account we created, and we call the function for our username

and password

Once this validates correctly, done with the first part; now, let us test our bot by the following someone.

my_bot.follow("name of person")

Our bot will follow whoever account or username we input here.

Hay, before you start wondering why I am not testing it after every new line of codes is because Instagram will notice we are running a bot and block us.

We have to write our codes first, and then I will show you how to create a wait time, so our bot looks like a student.

Next, we set our bot to follow multiple users.

my_bot.follow_users(["user", "user","user"])

This line will set up an array of users, which our bot will run through and follow at once.

my_bot.upload_photo("image.jpg", caption= "my first instagram bot and i am testing it")

We will set our bot to upload images from our local machine to our Instagram page.

We can also call the caption, which writes a caption for our image.

Note that since our image is stored on the desktop, it automatically pics it; otherwise, specify the directory where the image is located.

my_bot.send_message("hello friend, i am a bot and i am trying to breath", "username")

We can set our bot to send a private message to a user on Instagram by calling the > .send_message tag, which will allow set the message and the user we wish to send a message to.

my_bot.like_user("username", amount=5, filtration=False)

Setting our bot to like a user post is one of the things we can do with our bot by calling the function .like_user, calling the username of the user, and setting the number of posts to like.

Filtration is set to False, which means no post will be excluded from our count.

user_id = my_bot.get_user_id_from_username("username")

media_id = my_bot.get_last_user_medias(user_id, 1)

my_bot.comment(media_id[0], "this is cool keep it up")

To understand how to comment, we must first get the userID of the person’s post we want to comment and pass in the username as an arg.

We will get the media of the username and comment of the 0

which is the last media starting from the latest; remember that Python starts counting from 0 and not 1 so 0 is the latest.

my_bot.logout()

We log our bot out.

Before you run this code, Instagram will notice that we are running a bot as the commands are too fast and do not have the feel of a human user.

Therefore, we will add a sleep(30) which allows our bot to wait for some time after running one line of codes.

Wow, we just finished creating our Instagram bot.

You can run it via terminal python .\bot.py.

I hope you find this article interesting; please like, share, and follow for more articles.