VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-make-a-twitter-bot-in-python/

⇱ How to make a Twitter Bot in Python? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to make a Twitter Bot in Python?

Last Updated : 15 Jul, 2025

Twitter is an American microblogging and social networking service on which users post and interact with messages known as "tweets". In this article we will make a Twitter Bot using Python.

Python as well as Javascript can be used to develop an automatic Twitter bot that can do many tasks by its own such as:

  • Retweets the tweets with particular #hastags.
  • Favourites/Likes the tweets with particular #hashtags.
  • Follows the users who tweets with particular #hashtags.
  • Can also DM the users if granted with the permission.

Requirements

Install Tweepy 

For all this we will need a Python library called Tweepy for accessing the Twitter API. We can install tweepy in three ways:

1. Using pip command

$ pip install tweepy

2. Clone the GitHub repository of tweepy

$ git clone https://github.com/tweepy/tweepy
$ cd tweepy
$ pip install

3. Cloning the repository directly

$ pip install git+https://github.com/tweepy/tweepy

Sign up for Twitter Developer Account

  • Sign up for a separate account for your Twitter Bot and then apply for Twitter Developer Account following this link https://developer.twitter.com/en/portal/petition/essential/basic-info 
  • Enter the necessary details and await for your mail confirmation. Once confirmed, click on Create an App option.
  • Enter the necessary details to generate the secret key and access tokens.
  • Copy the keys and keep them safe.

Developing the Twitter Bot

Make a file twitterbot_retweet.py and paste the following code.

Now make another file to specify what should your bot do. Name it config.py

Edit the #hashtag according to your choice and the like or follow option to either True or False.

Next make a file credentials.py and paste your access tokens carefully in between the single quotes ' '.

Deployment

Run the twitterbot_retweet.py file from your Command Prompt/Terminal with this command.

$ python twitterbot_retweet.py

And it works!!

Comment