How to Make an Instagram Bot With Python and InstaBot?
Last Updated :
16 May, 2022
In this article, we are going to see how to make an Instagram bot using Python and InstaBot.
Bots are really common these days to send messages, upload photos, send wishes, and many more things. Bots reduce our work, save time. Today we are creating an Instagram bot that can do the following things.
Functions performed by the bot
- Follow one or more of friends.
- Unfollow one or a list of persons.
- Unfollow everyone.
- Count the number of followers of any user.
- Send messages to followers or a list of followers.
- Send like on chat.
- Post photos.
Instabot library: It is a script of promotion and API Python wrapper for Instagram.
pip install instabot
Login
Before performing any of the login() functions we need to import instabot library and login first.
Python3
# Import instabot library
from instabot import Bot
# Create a variable bot.
bot = Bot()
# Login
bot.login(username="your_userid",
password="your_password")
Output:

Follow
To follow one friend we can use follow() function.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# Follow
# To follow single person.
bot.follow("geeks_for_geeks")
Output:

To follow many users we need to make a list of usernames first then follow using the "follow_users" function.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# Follow
# To follow more person.
list_of_user = ["user_id1", "user_id2", "user_id3", "...."]
bot.follow_users(list_of_user)
Unfollow
To unfollow one person we will use unfollow() function.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# To unfollow a single person.
bot.unfollow("geeks_for_geeks")
Output:

To unfollow many people make a unfollow list then use the "unfollow_users" function.
Python3
from instabot import Bot
bot = Bot()
bot.login(username = "your_username",
password = "your_password")
# To unfollow more person.
unfollow_list = ["user_id1", "user_id2", "user_id3", "..."]
bot.unfollow_users(unfollow_list)
Unfollow everyone
Here we will use the unfollow_everyone() function to unfollow everyone into our accounts.
Warning: Please use this part of the code only if you really want to unfollow everyone.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# Unfollow everyone!
# To unfollow everyone use:
# Please use this part very carefully.
bot.unfollow_everyone()
Count the number of followers
We can check the number of our own followers or anyone followers using the "get_user_followers" function. This function makes a list of followers id.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# Count number of followers
followers = bot.get_user_followers("geeks_for_geeks")
print("Total number of followers:")
print(len(followers))
Output:


Send messages
To send a message to a single person is simple using send_message() function.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# Message
# To send message to a single person.
message = "I like GFG"
bot.send_message(message, "geeks_for_geeks")
Output:

To send the same message to many people.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# Message
# To send same message to many follower.
message = "I like GFG"
list_of_userid = ["user_id1", "user_id2", "user_id3", "..."]
bot.send_messages(message, list_of_userid)
Send Like messages
To send like make a list of the user then using the "send_like" function. The bot sends like to friends according to the list in the chat.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# Send like in messages
# To send like to one or more person.
send_like_list = ["user_id1", "user_id2", "user_id3", "..."]
bot.send_like(send_like_list)
Output:


Post Photo
To post photos on Instagram use we need to check whether the photo is in the given ratio. If the photo is not in the given ratio we need to resize it. The simplest ratio is 1:1.
Python3
from instabot import Bot
bot = Bot()
bot.login(username="your_username",
password="your_password")
# Post photos
# Photos need be resized and, if not in ratio given below.
# jpg format works more better than others formats.
# Acceptable Ratio of image:- 90:47, 4:5, 1:1(square image).
# Keep image and program in same folder.
# -----------------------------------------------------------
bot.upload_photo("filename.jpg", caption="Write caption here.")
Output:


Similar Reads
Make an Instagram Bot With Python Instagram is a powerful social media tool that you can use for marketing or networking. However, to successfully do any of that you need to have a good heavy follower base. You can't simply share a post with 50 followers and call it successful marketing. No matter what your goals are, having a large
6 min read
Creating Instagram Filters With OpenCV and Python Social and Photography apps such as Instagram, Canva, Snapchat, Picsart, etc. provide a bunch of filters to apply to our portraits and allow us to stylize them according to our choices and needs. An Image filter is a process of modifying an existing image by changing color, hue, sharpness, shade, an
6 min read
Send Message on Instagram Using Instabot module in Python In this article, we are going to see how to send messages on Instagram using the Instabot module in Python. Instagram is a nice platform for chatting but when it comes to sending the same message to all friends this is a really boring and time-consuming task especially if you have a large number of
2 min read
Instagram Bot using Python and InstaPy In this article, we will design a simple fun project âInstagram Botâ using Python and InstaPy. As beginners want to do some extra and learning small projects so that it will help in building big future projects. Now, this is the time to learn some new projects and a better future. This python projec
3 min read
Automate Instagram Messages using Python In this article, we will see how to send a single message to any number of people. We just have to provide a list of users. We will use selenium for this task. Packages neededSelenium: It is an open-source tool that automates web browsers. It provides a single interface that lets you write test scri
6 min read