Let’s focus on business. We’re creating a Discord bot that hangs around on our server and waits for webhooks from Ko-fi. With Ko-fi, you can effortlessly collect contributions to your PayPal account. You don’t need a corporate account with PayPal to set up webhooks, making it excellent for demonstrations and small-scale contribution processing.
However, Patreon also offers a Discord bot for donations and lets you set Discord roles as contributor benefits. We are doing something similar, but simpler.
The tutorial’s code is accessible on GitHub (https://github.com/mistval/premium or kahoot ninja spam). Follow the following links to GitHub if you suspect you may be missing anything.
Create a Bot account
To get started, we need a bot account. Creating a bot account requires a user account. Create a new user account here.
To create a bot account, we:
Create an application on the developer portal.
Developer portal screenshot Provide some basic application information (the CLIENT ID may be seen here).
registration form filled in
A bot user linked to the program.
If you toggle the PUBLIC BOT switch, a token will be displayed. It is vital that you refresh your bot token if you ever leak it. Anyone with your bot token may manage your bot’s account, causing possible lasting problem for you and your users.
Screenshot of “a wild bot has emerged” To add a bot to a guild, just use the following URL and go to it in a browser.
On Discord: type !authorize?scope=bot&client id=XXX.
Add the bot to your testing guild
I now see the bot in my test guild and I may approve it. But we’ll put that right shortly.
In Node.js, create a project and install Eris (the bot library we’ll use), Express (a web application framework we’ll use to establish a webhook listener), and body-parser (for parsing webhook bodies).
Eris Express + Body Parser
Bot is active and responsive
Let’s start small. Let’s get the bot up and ready to react. This just takes 10-20 lines of code. Once you have the bot token, build an Eris Client instance, provide it your bot token, and subscribe to events on the Client instance. Then, instruct the Client to connect to Discord. To illustrate this, we’ll hardcode our bot token into the bot.js file, although this is a best practice for projects using config files and Git excludes.