Creating a Bot

Hey there bud, you might want to check our GitHub!

So, you wanna make your own bot huh? Well, if you don't already, you really should get some prior programming knowledge to assist you along the way. You don't wanna just copy someone else's code, do you? You wanna understand what the hell it is you've written!

The most popular languages Bot Admins use are Python, Node.js, and PHP.

## Requirements

Before you start coding all sorts of different things, you first need the following items before getting started:

1. A bot idea
	* First of all, what is it that you want to create? You need to have an idea of what you want your bot to be. If you already do and want to get straight into it, perfect. If not, you can head over to our Facebook Group and check for any ideas people may have for bots but are too lazy to do themselves!
2. A social media page
	* Once you have your idea, go ahead and create your Facebook page or Twitter account where the bot will be posting. For the effects of this tutorial, we will be mostly working with Facebook.
3. Hosting
	* Your bot needs to run somewhere. This could be your own computer, a Raspberry Pi, a dedicated server, or renting a VPS from Cloud services (such as AWS, Google Cloud, Digital Ocean, Azure, etc...). Check our Recommended VPS page if you need help picking one.

Once you have these things, you can get to coding your bot.

## Facebook Bots

Facebook bots can be a lot of fun to write and watch! And they're simple, too: as long as you can make requests to the Facebook API, you can use any language you want! Even batch with CURL.

### Getting Your Token

A token is a sort of access code or "key" that allows a script to make requests to the Facebook API on the Page you just created. This key is unique and should **never** be shared with anyone. Someone who has your key could potentially steal your page and post without your consent!

There are a couple of ways to generate a key for your page:

1. Paintmin's Token Tool **(currently not working)**
	* Simply head over to Paintmin's Bot Access Token Tool and generate a key.
2. Create your own token with Facebook Developer Console
	* *Check out this video for a full tutorial.*
	* Alternatively, check this text guide, based on the same instructions as in the video above.

After doing this, you should have your token! Save it somewhere safe!

### Preparing your coding environment

Often this is as simple as downloading the language runtimes you wish to use (node.js, Python, etc.) and installing a text editor for code (Sublime Text, Visual Studio Code, Notepad++).

If you need assistance or want to dive more in-depth with this and set up a proper Linux-based development environment (even on Windows!), then check out the Creating a Bot/Setting up a development environment guide.

### Coding Your Bot

Great! Now that you have your token and your coding tools, you can get crackalackin'. Once you have written the bot, you need to make it able to post to Facebook itself. We have several guides on how to do this:

* Node.js (JavaScript)
	+ For a more in-depth look at the 'fb' node module and common API operations, click here.
* Python
* PHP

### Automating Your Bot

Now that you have a working bot and have verified that it can successfully post in your page, you need to find a way to automate the posting process. This is where the hosting comes into play.

Note: The frequency of the posts varies from one idea to another, but if you are not sure then we recommend setting it hourly. This is a healthy posting frequency which will not get you flagged for spam, or run too many API calls frequently.

* Your own PC
	+ If you wish to use your own PC to run the bot, you need to find a way to make it post automatically. With Windows you can use Task Scheduler to have it run the script at a set interval. Note that this means your PC would have to stay on 24/7 for the bot to run constantly. This is not a preferred method, and other methods are encouraged, but there are always exceptions (Perlin Art Bot 7403).
* Raspberry Pi
	+ If you own a Raspberry Pi, you can run the scripts from it and simply have it host the bot as long as you have power and a steady internet connection
* Virtual Private Server (VPS)
	+ If you rent a virtual machine from a Cloud Service provider, you can run the bot from there and never worry about it. Some VPS providers allow for a 'free tier', while others can charge as low as $5 a month for all your bot hosting needs.