It’s Alive! How to Make a Twitter Bot in Five Steps

Twitter Bot Use Examples

Twitter bots tend to get a bad rap. And sure, tricking your followers (and followees) into conversing with a glorified algorithm could be seen as morally questionable. But beyond the spam and the impersonal nature, there’s actually a lot of good that Twitter bots can do.

You can use Twitter bots to schedule your tweets so that they go out at the right time (even if you’re not available at that time). You can use them to pass on important details by designing them to automate responses to specific queries. You can use them to automatically add to or delete people from your Twitter lists. And they give you the power to stay active on social media without being so active that you don’t get anything else done.

For programmers, they offer another clear advantage: They give you a great coding project you can do right now. So, what do you say? Let’s create a Twitter bot. 

How to Make a Twitter Bot in Five Simple Steps

Well, Let’s Get Some Stuff Out of the Way First

Before we get started, it’s worth noting that there are different kinds of Twitter bots, and some of them are in direct violation of Twitter community rules and policies. In fact, Twitter has laid down a list of automation rules specifically for dealing with Twitter bots. Familiarize yourself with these rules and always remember that your bot will be interacting with real people, so you shouldn’t do anything that will create a bad experience for someone on the other side of the network. 

Keep it legal; keep it nice — or you could end up getting kicked off of Twitter (to say nothing of the reputational damage bad bots can do to your image). Always remember that you are responsible for what your bot does online.

With that out of the way, let’s get started. And when it comes to Twitter bots, square one is setting up an application.

1. Get Developer Access

It’s probably not too surprising that in order to create a Twitter bot, you need a Twitter account. If you’ve already got an account and want to work with that one, you can configure the account to create a new Twitter application — and that means you’ll need Twitter developer access.

To do that, go to the Twitter developer site and log in (or create a new account). You’ll need to apply for a Twitter developer account and to do that you’ll need to provide some personal information for account verification.

You’ll be asked, “What is your primary reason for using Twitter developer tools?” Select making a bot and then click next. Verify your information (yes, including your phone number), and click next. You’ll then be directed to a page that will ask you some questions about how you intend to use your Twitter Application, followed by a page where you’ll need to review and accept the developer agreement. Submit that and confirm via your email account. Just be warned, sometimes the application review process can take a while.

Okay, it’s time to start building the app.

2. Build the App

Before you can set your Twitter bot loose, you’ll need to create a Twitter app to power it. So, go to the Twitter developer page, and click the Create an App button. You’ll need to complete these steps before acquiring your consumer keys (also called API keys) and access tokens you’ll need to authenticate your permissions.

You’ll be taken to a page that will need you to fill in certain details about your app.

Build the App

  • App name
    Although this is listed as app name, it’s really more of a user name. Who will be sending the tweet? So, if you want your bot to tweet as Devmountainbot, then that’s what you’ll put into this field.
  • Application description
    What will your app be doing? What’s the purpose behind it? For example, if you want it to retweet specific content related to coding bootcamps, then that’s what you’ll need to specify. 
  • Website URL
    The source of your tweet; this should be the URL of your website. You can use your Twitter handle as a placeholder if you don’t have a website.
  • Application purpose
    Why are you making this app? What will it do? If this sounds familiar, it’s because these are essentially the same questions you answered in the ‘Application description’ field. This is more for Twitter’s benefit, though, as the company will want to make sure that you aren’t designing an app to violate Twitter’s terms and conditions.
  • Other
    You will have the opportunity to add additional details, but they aren’t required.

Try to fill out these fields as accurately and with as much detail as possible. 

3. Specify the Development Environment

One of the great things about developing bots for Twitter is that you can use pretty much any programming language you’re comfortable with. JavaScript, Python, Ruby… the list goes on and on. Want to get some practice using code you’re not as familiar with? Creating Twitter bots is a great way to do that.

Of course, detailing how to use each of these languages to build Twitter bots is beyond the scope of this article. The good news is that Botwiki has a number of easy to follow tutorials for specific programming languages. But to keep things as simple as possible, let’s just stick with Amit Agarwal’s extremely useful Twitter bot Google script.

Using this script can help you understand some of the processes that go into bot creation. Likewise, there are a number of other Twitter Bot Maker programs available online.

4. Connect Your Development Environment to Your Twitter App

Your app powers your bot. Your development environment tells it how to behave. You need both for your bot to work, and they need to be able to communicate with one another. To create this connection, you’ll need the consumer keys and access tokens you acquired when you built your Twitter app.

Connect Your Development Environment to Your Twitter App

On the Twitter developer site, navigate to the app dashboard and select your app, then select keys and tokens (it should be between App details and Permissions).

Here, you’ll have the option to generate or regenerate Consumer API Keys, as well as your Access token & access token secret. These keys will allow you to access and control your account, so make sure to keep them to yourself.

With your API key, API secret key, Access token, and Access token secret firmly in hand (so to speak), now go to the Agarwal Google Script, and put those keys into the designated fields. This will link your development environment to your app and set the stage for you to finally start programming your Twitter bot.

5. Start Programming Your Twitter Bot

The Google script makes programming very simple, but you’ll still want to take some time to explore your options here. You’ll see different fields such as Twitter Search (what your bot will be searching for), Action (what your bot will do in specific situations, such as sending a public reply, retweeting a tweet, adding followers to Twitter lists, etc.), and Text (text that will appear when a specific action is taken).

Start Programming Your Twitter Bot

Just remember that if you’re not careful, you and your bot could inadvertently end up banned from Twitter. Keep the automation guidelines firmly in mind and make sure you aren’t creating a bot that’s going to send out unwanted spam.

Great. Now, Let’s Start Programming

Web development is a big deal. That’s why we’re going to tell our bot to send out a public reply to every tweet that mentions “web dev.” Our reply will include a link to the Devmountain Beginner’s Guide to Web Development.

To do this, we’ll go to the Twitter Search field and add “web dev.” Then, in the Action field, we’ll select send public reply from the drop-down menu. Finally, in the Text field, we’ll say something like “Web dev is taking the world by storm! Check out our free Beginner’s Guide to Web Development:” Then we’ll click the Save button.

And that’s it. We just programmed our Twitter bot to take a specific action in a specific circumstance. Let’s try another one.

How about retweeting? For this, we’ll program the bot to retweet content that includes the hashtag #devmountain. So, when Devmountain shows up in conversations, our bot will automatically retweet those conversations from our account. You can help weed out lower quality tweets by setting a minimum favorite count, which will tell the bot to only retweet content that has been favorited by a specified minimum number of people. For this, let’s set the minimum favorite to one (but you can set it as high as you’d like, or not set it at all).

In the Twitter Search field, enter the hashtag followed by the minimum number of favorites. It should read as follows: #devmountain min_faves:1.

Then, in the Action field, select quote tweet. Finally, in the Text field, let’s add “See what people are saying about Devmountain!” Then, we click Save.

Cool, right? How about one more. Let’s tell our bot to send a nice message to new followers.

To do that, we’ll put our Twitter handle in the Twitter Search field, then select DM followers in the Action field. Then in the Text field, we type “Thanks for following Devmountain! Check out our site for more cool coding content.” Don’t forget to click Save.

And there it is: a functioning Twitter bot ready to help you out on social media. All that’s left is for you to check to make sure that everything is working the way it’s supposed to. Wait a day or two, and then click Check on the script page, and you’ll get a nice view of every action your bot has performed.

Building a Better Bot

Twitter bots are useful for anyone who wants to automate basic Twitter activity. But more than that, they’re a great way for beginner (and experienced) coders to play around with programming languages and tools. So once you’ve laid down the groundwork and built your first bot using this tutorial, why not take things further? Pick your favorite programming language and start building a better bot today.

See also:

Related posts

Request information

Get Started Today

Get more information about:

  • Curriculum, programming language and technology covered
  • Daily and weekly course structure
  • Financing and career support

Step 1 of 2

All fields are required.

Request information

Step 2 of 2

All fields are required.

*Consent to Contact. By providing your information, you consent to receive occasional special promotional offers and educational opportunities by email via automated technology from Devmountain and Strayer University. Consent is not required to purchase goods or services.