How to make a bot for Fediverse/Mastodon, Twitter, Tumblr, and other networks.
📅 November 28, 2022
So you want to make a friendly/useful/artistic online bot and probably have a bunch of questions, like How often should my bot post? or Why am I getting this weird error message? and How do I even make a bot? And what IS a bot?
Hopefully this ambitiously titled guide will answer your questions — and you are always free to ask for more help in the Botmakers community.
Page content¶
- General
- What kind of a bot should I make?
- How do I make a bot?
- Should I run the bot as an always-on app, or use a scheduler?
- Do I need to set up a separate account for testing my bot?
- Do I need to disclose if an account is a bot?
- Mastodon
- Wrap up
— vennsplain (@vennsplain) November 2, 2017
you don't want to make conceptual art, you want to make a twitter bot.
— Adrian 'The True Imported Polish Ham' (@yo_adrianididit) December 2, 2020
General botmaking tips¶
What kind of a bot should I make?¶
The bottom line is this: don’t let your bot annoy people. Try to avoid interacting with people who don’t follow your bot or knowingly initiate the conversation either through a post with your bot’s handle, or a direct message.
There certainly are clever examples of bots who do interact with random folks who didn’t explicitly opt-in, but this is a bit of a gray area and you should use your best judgement here.
On Mastodon, people often add the #nobot
hashtag in their profile bios to indicate that they do not wish to interact with automated accounts, so definitely look for that.
Also, just because some information is public, it doesn’t mean it deserves exposure.
And it hopefully doesn’t even need to be said that you shouldn’t make bots that harass people, post spam, or do any other malicious activity. Remember, bots should always punch up, never punch down. And people don’t seem to care too much about “ebooks” accounts.
What are your favorite bots to follow?
— @[email protected] 🤖💾🎨 (@botwikidotorg) October 26, 2020
As for what your bot should do, well, here are a few tips:
- browse Botwiki and get inspired by what others made
- see what kind of bots are most popular in the fediverse and on Twitter
- check out various APIs, images, and public data sets you can use
- learn more about the API you’re using and maybe even “exploit” some of the quirks
- the Botmakers Slack group has channels where people share their ideas and look for collaborators
For even more inspiration, check out these essays and articles.
Making a good bot is not always a straightforward process, with steps to go through. Sometimes the decisions you make affect each other, for example, you can start with an idea and then decide what language and hosting platform you’ll use.
But you can also first look at the various platforms you can use to host your bot and play with their strengths and limitations. More on that in an upcoming section.
What are the most popular Twitter bots? And why you shouldn't care all that much.https://t.co/hL7bOypyrm pic.twitter.com/apnYPGEvm2
— @[email protected] 🤖💾🎨 (@botwikidotorg) October 7, 2019
How do I make a bot?¶
With most of the non-technical questions out of the way, it’s time to actually build your bot.
Botwiki has plenty of tutorials and there are many open-source bots and Twitter bot project templates on Glitch that you can use.
Just find one that’s close to your own bot idea and take it from there.
have silly bot ideas and then make them! it’s easier than you think! they don’t even have to be good ideas!
— The Festival in theatres Aug 14 (@pillowfort) July 28, 2018
Should I run the bot as an always-on app, or use a scheduler?¶
This depends on the type of a bot you’re making, so for bots that respond to messages or certain real-time events, it makes to run them as persistent apps. But unless needed, it seems that most people prefer to schedule their bots.
Do I need to set up a separate account for testing my bot?¶
This is up entirely up to you, but here’s how some people approach it.
How do you usually test your bot before you make it public?
— @[email protected] 🤖💾🎨 (@botwikidotorg) June 11, 2021
Do I need to disclose if an account is a bot?¶
Yes!
On Mastodon, this changes how the network sees the account. According to this helpful StackOverflow answer:
- the bot gets a “bot” badge
- its posts don’t contribute to trending tags
- and the bot is marked as a “Service” instead of a “Person”
If you’re making a bot on Twitter, refer to the Developer Policy that states that if you’re operating an API-based bot account you must clearly indicate what the account is and who is responsible for it.
How often should my bot post?¶
Alright, you might have a rough idea what your bot is going to be posting about now, great! How often should it post though?
Some networks, like Twitter, have limits on how often you can call their API, so you should keep those in mind.
Other than that, it’s all about striking the right balance. If your bot posts every time a certain event happens, it’s okay if your bot posts more frequently.
But also consider that some people don’t want their home timeline cluttered with just one account, so for bots that don’t work with real-time data, spacing the posts out makes a lot of sense. As I said above, one good rule to follow is to make sure your bot doesn’t annoy people.
How often should a Twitter bot tweet?
— Ian Brown (@igb) June 22, 2017
Hey Twitter bot makers! How often does your bot tweet? It's a crucial factor and I want to see where you set that dial.
— nick is on Mastodon (@nickdrawthing) December 1, 2020
If you don't feel like the poll options suit you, please comment (feel free to comment anyway)!#botally #twitterbot
There are bots that post every hour, once or twice a day, or even just once throughout the whole year.
Here are some thoughts from a member of Botmakers:
Hard question. I look at it as a logarithmic-scale line starting at once a minute and ending somewhere around once a week or month.
There is a hard upper bound of 25 tweets per 15 minutes per account.
There are multiple approaches you can take to figured this out, and they’re mostly situational:
The easiest approach is to have your bot post as often as it can, like if you’re running @congressedits, you want to catch all edits.
If you have too much information for this and need to attenuate the flow, or if your corpus is fixed or precomputed, then it comes down to questions like, do I want to follow this bot myself? How often would I like to hear from it if so? Is there prior art that I am mimicking? If it’s a fixed corpus, how long should it run before it ends? How often would others like to hear from it? should it be annoying/how much so?
If you’re unsure, post every 30 or 60 minutes, tweak it later if you don’t like it.
— @air_hadoken
Another thing to consider is, do you want your bot to post on the hour? Or is it better to offset the time a bit so that it doesn’t clutter its followers timeline when all the other bots they follow post.
Do your scheduled bots post exactly on the hour? For example, at 9am, 1pm, 5pm, etc.
Or do you schedule your bot for a less common time, eg: 9:15am, 1:30pm, or something completely random each time the bot posts?
Or how do you deal with repeating content?
For bots that post random stuff from a list, do you post completely randomly, or do you tweak your bot to, for example, avoid posting the same thing twice in a row?
What strategies do you use?
Do I need to attribute content posted by my bot?¶
Am I responsible for everything that my bot does online?¶
Where should I host my bot?¶
There is a number of platforms you can use depending on how much you’re willing to spend (no worries, free options exist) and how complex your bot is.
For simpler bots, check out Cheap Bots, Toot Sweet! and Cheap Bots, Done Quick!, a pair of sites that let you make Mastodon and Twitter bots, respectively, with Tracery, and completely for free.
Want to make something more advanced? Check out the Creative Bots project.
For a comprehensive list of available hosting platforms, see the Hosting platforms page on Botwiki.
Why is my bot not working?¶
The API you use to automate your bot will usually return an error message that should help you understand why your bot stopped working.
For example, if you’re using the Twit library, here’s how you can see the error message:
T.post('statuses/update', { status: 'hello world!' }, function(err, data, response) {
if (err){
console.log(err);
}
});
It’s possible that your bot posts or reads data too often, then you just need to adjust the frequency. It’s also possible that your bot was suspended, in which case you might also get an email notification and instructions on what to do next.
If you’re not getting any error messages, and the bot doesn’t seem to be suspended, the problem might be with your code. It’s perfectly fine to ask for help, in fact, that’s why the Botmakers community exists.
How do I make my bot accessible to everyone?¶
Check out this handy guide on this topic!
How do you typically handle image description for your image bots?
Feel free to share any useful tips!
My bot doesn’t have enough followers¶
Share your bot with @botwikidotorg and the Botmakers community! Try adding relevant hashtags to your bot’s posts every now and then. Hashtags are particularly important on Mastodon, so bots posting there should always include some so that others can find them.
But at the end of the day, learn to enjoy the process and do it for the fun. Getting a ton of followers shouldn’t be the goal and it’s often about luck!
Use the same email (sort of) for multiple accounts¶
One neat trick you can use when registering for a new account is adding +SOMETHING
to your email address, for example, [email protected]
. This will let you use the same email address for multiple accounts.
Mastodon bots¶
Can I make a bot that searches through the public timeline?¶
Yes, but the type of content you can search for can be limited. For example, on mastodon.social instance you can only search local accounts and hashtags, but you can’t search the individual toots.
How do I get the RSS feed of my bot?¶
To get the RSS feed of your bot’s output, add .rss
to your bot’s URL, so for example:
https://botsin.space/@southpoleviews
will become
https://botsin.space/@southpoleviews.rss
Should I automatically delete my bot’s old posts?
Doing this will help ease the load on the instance, especially if the bot generates images or other media.
Do you automatically delete your bots' old posts?
But most importantly, consider donating money to the instance admin!
Twitter bots¶
Note on needing a phone number¶
One tricky part of making a bot for Twitter is that if you want your bot to be able to actually post on Twitter, rather than just read from it, you will need to add a phone number to your account.
There is a few ways to solve this:
- you can remove the phone number from your current account by texting STOP to a Twitter shortcode based on your country (40404 for US), and associate it with a new one
- you can sign up for Google Voice (Skype number won’t work, because Skype doesn’t let you receive text messages, which you will need to verify your phone number)
- this tutorial by Molly White explains how to transfer your Twitter app to another account
- see also: Friendly Twitter Bots and Write Access
How can I use the same developer account for all my bots?¶
Check out the Tools section on the Resources for Twitterbots page. There’s also a few helpful tutorials:
- How to Create Multiple Bots With a Single Twitter Developer Account by Jelilah Anofiu
- Many bot accounts using 1 Twitter Developer account by Ru
- brief walkthrough by Ranjit Bhatnagar
Can I make a bot that tracks keywords or hashtags?¶
From Twitter’s Automation rules:
Automated Retweets: Provided you comply with all other rules, you may Retweet or Quote Tweet in an automated manner for entertainment, informational, or novelty purposes. Automated Retweets often lead to negative user experiences, and bulk, aggressive, or spammy Retweeting is a violation of the Twitter Rules.
As explained above, there are some gray areas when it comes to automating certain actions on Twitter, including automated retweets.
One way around getting your retweet bot suspended is to make your bot private. This way you can follow the topics you’re interested in without bothering anyone since notifications from private accounts don’t show up to people your bot is not following.
The biggest drawback here is that it will be harder for others to discover your bot, and as of February 2017, there is no way to approve follower requests for a protected account via the Twitter API, so you will have to handle follower requests manually.
Stop the Twitter email spam¶
Twitter doesn’t really differentiate between “regular” user accounts and bots. Bots are really just automated user accounts — in fact, you could easily add some automation to your own account while you’re still using it as a human.
One of the problems with this setup is that Twitter will happily send emails and other notifications to your bot as if it was a real person, unless you specifically opt-out.
tfw you make twitter bots pic.twitter.com/So0L8rbLf3
— Ben Brignell (@benbrignell) April 25, 2018
The most important part of setting up a new twitter bot is THIS LITTLE BUTTON pic.twitter.com/p7wTFMjiSo
— foone (@Foone) March 22, 2018
How can I apply for the #GoodBots label?¶
You can’t quite yet, but hopefully soon! (Learn more here.)
Wrap up¶
I hope this guide will help you deal with some of the biggest questions and challenges of making friendly online bots. Be sure to join us in the Botmakers community. We are artists, journalists, educators, tinkerers, bot enthusiasts, seasoned developers, and always happy to help a fellow botmaker out 🙂
If you’d like to leave me feedback and suggestions for this guide, feel free to send me an email!
And you can see more of my tutorials here.
Not all bots are bad. And the Twitter Rules allow for some automation. There are tons of fun and creative bots that make Twitter better — check out @tinycarebot and @everycolorbot.
— Twitter Comms (@TwitterComms) May 22, 2020
Create a quick chart of your Twitter bots with this handy @glitch project! via @fourtonfishhttps://t.co/wH61oWMcad #dataviz pic.twitter.com/PdlZy9s6YR
— @[email protected] 🤖💾🎨 (@botwikidotorg) May 10, 2021
Special thanks¶
Enjoyed the tutorial?
Consider supporting Botwiki!
Latest from the blog
Eight years of Botwiki, and 2,000 bots
Happy birthday, Botwiki!
Cheap Bots, Done Quick suspended, this time for good
So long, and thanks for all the bots.
Twitter shutting down free access to their API on February 9
I keep saying it's an end of an era quite often these days.