Open In App

How to Make an Instagram Bot With Python and InstaBot?

Last Updated : 16 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads