This code will guide you on how you can make your own Twitter Bot.

Overview

Do you use Twitter? If so, then you must come across some of the bots that like, retweet, follow, or even reply to your tweets. But have you ever wondered how they are made? Well, it's easy as filling water in a bottle. Haha! It's really not rocket science. So, let's get started and make a bot.

image

In Python, the twitter bot is just a few lines of code, less than 30.

Prerequisites for making one (Bot)

- tweepy module in Python.
- A twitter account, which you want to make a bot.
- Twitter developer account.

Applying to the twitter developer account

To apply for the developer account on twitter, follow these steps:

  • Go to this link.
    You will get this kind of website after you visit the mentioned link. Alt Text

Make sure you've logged in to your Twitter account on which you want to make a bot.
Here, I'm using my new account BashWoman to make a bot, which will like, and retweet the hashtag #python3.

  • Click on apply, after doing that this type of screen will show up.
    Alt Text Select, apply for a developer account.
  • After this, you will get a number of options, why you want to apply for the developer account, here we are making a bot, so I will select Making a bot.

Alt Text

  • Now, on the next page, you have to fill some details. Do that.

Alt Text

  • Twitter will ask you some questions related to how you would use this account and the twitter data. We are just making this bot to like and retweet the posts so, select that only.

Alt Text

And

Alt Text

Else select no, just to keep it simple. Enter all the details you'd do with this bot.

  • After filling all the details, you'll get an agreement page. Just accept all the terms and conditions. And then click on Submit application.

Alt Text

  • You will get a confirmation mail. Once you confirm that, a new window will open like this.

Alt Text

Click Get keys.

  • After this, what we wanted by this developer account is the keys. Save them somewhere, you'll need them soon.

Alt Text

Let's Code and understand it

Alt Text

You see there are no more than 30 lines in Python. Let's understand each and every line.

import tweepy
import time

To communicate with Twitter API, we need some module, here we are using tweepy. You can install it easily.

pip install tweepy

Once you install the module, write some more code.

# Authenticate to Twitter
CONSUMER_KEY = '
   
    '
CONSUMER_SECRET = '
    
     '
ACCESS_KEY = '
     
      '
ACESS_SECRET = '
      
       '
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACESS_SECRET)

      
     
    
   

This is used to authenticate your Twitter account. Remember these keys are of your account, don't share them to anyone, else they can access your data. That's why I have made some variables in which I will store the keys.

These keys will be found in your developer account, which you've saved a time ago.

auth variable is created to authenticate the account, Twitter uses OAuth to do this.
And, after that, we will set the tokens.

# Create API object
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

This class provides a wrapper for the API as provided by Twitter. If you stuck somewhere, you can always refer to the tweepy documentation.

user = api.me()
search = '#python3'
numTweet = 500
for tweet in tweepy.Cursor(api.search, search).items(numTweet):
    try:
        print('Tweet Liked')
        tweet.favorite()
        print("Retweet done")
        tweet.retweet()
        time.sleep(10)
    except tweepy.TweepError as e:
        print(e.reason)
    except StopIteration:
        break

Finally, we will tell the program to look for the keyword #python3 in a tweet and the number of tweets that will be processed once in a day. If you want to like, you can use tweepy.favorite() , and for retweet tweepy.retweet(). The reason, I'm using sleep is, twitter has some guidelines, you must follow otherwise, your account will be restricted. There is a limit for liking the number of tweets. If it gives some error, we can use tweepy.TweepError so that we know, what went wrong.

Now, it's time for the deployment. You can use any platform, I have used Render.
After creating an account on this, create a cron job, you can schedule the time, I prefer about 10 to 15 mins. It means your bot will run every 10 to 15 mins so that it won't violate the Twitter guidelines and your account will be safe and not get restricted.

Here's my bot.

Alt Text

It's time to build your own bot. All the best.

Owner
Kunal Diwan
Hello I am Kunal . I am a Pre-Final year student in Computer Engineering . Building few things on web 🚀 and Developing Bots on TG .
Kunal Diwan
Python API client library for phpIPAM installations

phpypam: Python API client library for phpIPAM installation As we started to develop phpipam-ansible-modules we used an existing python library for ph

codeaffen 3 Aug 03, 2022
🛰️ Scripts démontrant l'utilisation de l'imagerie RADARSAT-1 à partir d'un seau AWS | 🛰️ Scripts demonstrating the use of RADARSAT-1 imagery from an AWS bucket

🛰️ Scripts démontrant l'utilisation de l'imagerie RADARSAT-1 à partir d'un seau AWS | 🛰️ Scripts demonstrating the use of RADARSAT-1 imagery from an AWS bucket

Agence spatiale canadienne - Canadian Space Agency 4 May 18, 2022
This discord bot preview user 42intra login picture.

42intra_Pic BOT This discord bot preview user 42intra login picture. created by: @YOPI#8626 Using: Python 3.9 (64-bit) (You don't need 3.9 but some fu

Zakaria Yacoubi 7 Mar 22, 2022
Bearer API client for Python

Bearer Python Bearer Python client Installation pip install bearer Usage Get your Bearer Secret Key and integration id from the Dashboard and use the

Bearer 9 Oct 31, 2022
May or may not be work🚶

AnyDLBot There are multiple things I can do: 👉 All Supported Video Formats of https://rg3.github.io/youtube-dl/supportedsites.html 👉 Upload as file

Arun 2 Nov 16, 2021
Fetch the details of assets hosted on AWS.

onaws onaws is a simple tool to check if an IP/hostname belongs to the AWS IP space or not. It uses the AWS IP address ranges data published by AWS to

Amal Murali 80 Dec 29, 2022
A Telegram bot for Minecraft names

MCTelegramBot About this project This bot allows you to see data about minecraft names in Telegram, it has a few commands such as: /names - Show dropp

Kami 5 May 14, 2022
Github-Checker - Simple Tool To Check If Github User Available Or Not

Github Checker Simple Tool To Check If Github User Available Or Not Socials: Lan

ميخائيل 7 Jan 30, 2022
Discord bot to administer IITD Study Servers (unofficial)

IITD-Bot Discord bot to administer IITD'20 Acad Server Commands hello to check if bot is online ?help to display this message ?set kerberos to set y

Aditya Singh 47 Dec 19, 2022
A wrapper for slurm especially on Taiwania2 (HPC CLI)A wrapper for slurm especially on Taiwania2 (HPC CLI)

TWCC-slurm-wrapper A wrapper for slurm especially on Taiwania2 (HPC CLI). For Taiwania2 (HPC CLI) usage, please refer to here. (中文) How to Install? gi

Chi-Liang, Liu 5 Oct 07, 2022
Set up recurring buys in Gemini

Overview Set up recurring buys in Gemini. Given some keys (Create API Keys), allows you to configure a recurring buy using the reduced API maker and t

Ahmad Abuomar 3 Jan 06, 2022
Python Client Library to interface with the Phoenix Realtime Server

supabase-realtime-client Python Client Library to interface with the Phoenix Realtime Server This is a fork of the supabase community realtime client

Anand 2 May 24, 2022
A Twitter Bot that retweets and likes tweets with the hashtag #girlscriptwoc and #girlscript, and also follows the user.

GirlScript Winter of Contributing Twitter Bot A Twitter Bot that retweets and likes tweets with the hashtag #girlscriptwoc and #girlscript, and also f

Pranay Gupta 9 Dec 15, 2022
Python SDK for the Buycoins API.

This library provides easy access to the Buycoins API using the Python programming language. It provides all the feature of the API so that you don't need to interact with the API directly. This libr

Musa Rasheed 48 May 04, 2022
Elemeno.ai standard development kit in Python

Overview A set of glue code and utilities to make using elemeno AI platform a smooth experience Free software: Apache Software License 2.0 Installatio

Elemeno AI 3 Dec 14, 2022
A script to automatically update bot status at GitHub as well as in Telegram channel.

Support BotStatus ~ A simple & short repository to show your bot's status in your GitHub README.md file as well as in you channel. ⚠️ This repo should

Jainam Oswal 55 Dec 13, 2022
Alienworlds-bot - A Python script made to automate the tidious job of mining on AlienWorlds

AlienWorlds bot A Python script designed to automate the tedious work of mining

5 Dec 23, 2022
This is a simple bot for running Python code through Discord

Python Code Runner Discord Bot This is a simple bot for running Python code through Discord. It was originally developed for the Beginner.Codes Discor

beginner.py 1 Feb 14, 2022
A telegram bot that can send you high-quality audio 🎧🎧🎧

Music downloader bot Still under development Please Report issues to improve this repo.I will try to fix bugs in next update Music downloader bot is a

Anish Gowda 36 Dec 06, 2022
Select random winners for a Twitter giveaway

twitter_picker Select random winners for a Twitter giveaway Once the Twitter giveaway (or airdrop) is closed, assign a number to each participant. The

Michael Rawner 1 Dec 11, 2021