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
from instabot import Bot
bot = Bot()
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" )
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" )
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" )
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" )
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" )
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" )
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 = "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 = "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_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" )
bot.upload_photo( "filename.jpg" , caption = "Write caption here." )
|
Output:


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
16 May, 2022
Like Article
Save Article