The Bot Appreciation Society Wiki
Advertisement

Twitter Bots[]

Visit this page!

Templates

Facebook Bots[]

If you don't know the basics of using facebook-sdk, refer to this guide: How to make a facebook bot (basics) If you know python, and are okay with reading a bit of api docs, you may skip the basics. Also you would need:

  • Python 3.x
  • IDE (preferably VS Code/Sublime Text/Atom)
  • Loads of free time
  • VPS/ Host (Anything is fine here, even your PC is okay if you can keep it on 24/7, otherwise if you can use Amazon's AWS, Google Cloud, Microsoft Azure, etc)

Here, i will be walking you through the process of writing the code, getting the access token, and just a sneak peak of scheduling your bot!  Now time for some coding! Lets say you want to make a Lottery Ticket Bot (classic example). Firstly we would need to generate lottery tickets, which are essentially random. So lets rev up our text editors. In my case, I'm using Sublime Text 3. If you are using Sublime Text as well, it should look like this to you (considering you're in a folder)

Start










Great! Now lets do some coding.

Considering python is basically just spicy English, it shouldn't be too difficult.

So after writing literally 3 lines of code, we come up with this

2







Cf906be5f5592d212956e1cea57cf647



But this doesn't quite look like a lottery ticket number, does it?

That fix should be easy, just a little for loop to insert a space within out number...

8ba8ebfcea3db23d73e47580bfc55b70




And overall, tweaking the code a bit to make it look better,

0b6024c7de3e4bec5e25419cf583ac4f








Basically i put everything into functions to make the code a bit more organized. This gives us the output

A32f7495c40ca49e97cb59022c8712be

the first output is the originally generated number and the second is the better looking version


That means, we are now ready to make our bot live on Facebook!


I am using my test page for this purpose, but it should be more or less the same for you people. After creating the page, head over to this site and get an access token for your bot!

[UPDATE 2021] It is now possible yet again to make your own token from scratch. Although keep in mind, this will limit some advanced features for your bot.You should do this only if the token tool website is down for some reason and you want to test your bot anyways.


I'm not going to dive deep on how to generate the token as Paintmin, the site owner and our Lord at The Bot Appreciation Society has a pretty detailed description of that on his site.

Now, store the token in your program in a variable with whatever name you want.

After that we need a function that can post the Ticket on Facebook.

Here's the code for the function:

F12aa7abaa422d5eb5017f00fef87672




If you're wondering why put_photo and not put_object, that's because Facebook blocks text posts from time to time and marks it as spam. So, we attach a 400*1 white image to make it seem like a regular text post. You can download the image from here

[UPDATE 2021] It is now possible to make text posts without attaching any image!

graph.put_object(parent_object = "me", connection_name = "feed",message = message)

Overall, this is how it looks:

617676bb05db401d36ac892259ca186b









Now its time to run it... and viola, It worked!

7b4bf84af85f98e552c2e00343dcb2af



Lets see if it actually posted anything or not.

7d6115b80da10c2724cc404d43d55560






Yes it did!

Now back to work...

We have to make our bot post the ticket to our page. For that, we make a minor adjustment to the end of the code:


E64dca1587e7c08f6433f57797440282



Lets see if it worked...

254a2d459132ad96fce84ba5746037e0






Yay! It worked perfectly!

Now we need the bot to do this every 30 minutes lets say, For that, we can use this god sent module called schedule. (use pip install schedule to get the module)

After that lets import schedule & time and shove everything in the main function to another function called job.

Ff7a623344a647380b0b253829dc734f

As you can see i also increased the number of digits in the random number we generated.













Now All you need to do is let the code run, and it will keep posting lottery numbers. Of course, posting lottery numbers wont make a bot fun. Try coming up with bot ideas, and integrate them with the code we just wrote. I'm positive you can code a brilliant bot as well!

-Semolini

(Admin of pages like Every Tom and Jerry Frame in Order, Blessed Bot 6009, Unmanned Cringe Bot etc...)


[UPDATE 2021] Semolini from 2021 here! I just wanted you guys to know that this is not a good way to generate random lottery numbers. Although it serves the purpose here for demonstrating how the Facebook api works pretty well, if you're into generating big random numbers (for some reason) , this is not the way to go. This script in the long run might hog a chunk of your processing power. This article gives you a pretty solid overview of what not to do and why not to do. That being said, best of luck on your bot adventures from all of us at The Bot Appreciation Society!

Advertisement