1. Making a Bot Account (Discord)#
Choose Social Media Platform: Reddit | Discord | Bluesky
In using this textbook, you will have opportunities to create and run social media bots. Here we will run through how to create a Discord account and set it up for running your own bots.
While we have made a fake version of Discord for you to test all the code in this book, we highly encourage you to make a Discord bot account and try it out for real!
1.1. Sign up for Discord#
We suggest making a new, separate Discord account, just for making Discord bots, since you don’t want to accidentally get your main Discord account banned or labeled as a bot. Also we suggest using a different password than you use for other accounts, since you might accidentally share it with your code.
Note: If you want to make a new account and you already have one, you may need to sign out from your current account, use a different email address, or use a different web browser (e.g., Mozilla, Google Chrome, Microsoft Edge, Safari).
1.2. Create your own Discord Server#
It is easiest to test your bot by creating your own discord server.
1.3. Create a Discord “Application”#
Note: Instructions are based on the official instructions here: https://discord.com/developers/docs/getting-started
In order for your bot to run, you must create a Discord “Application.” Go to the Discord Developer Portal and click “New Application”:
Make up a name for your app and press the “Create” button:
1.4. Get Discord Token#
In order to make your bot work, you’ll need to create a special password for your bot to use, which is called a “token.” Reset your token and save it somewhere (e.g., email it to yourself). You’ll need it later to let your bot log in.
1.5. Get Bot Invite Link#
Next we need to create an invite link so your bot can be added to different discord servers.
To do this use the OAuth2 tab for your application. (Note: if you see an option to set Authorization method, set it to “In-app Authorization”)
This may give you a bunch of options for permissions your bot might need. We’ve selected a good starting set of permissions to let you do most things you’ll probably want to do with your bot.
Now go to URL Generator to create an invite link for your bot. You’ll get a permission set of options again, where we’ve chosen the same permissions as before. At the very bottom there is an option to copy a the url, which is an invite link to your bot. Copy this and save it.
This invite link can be given to the owner of any discord server and they can use it to invite your bot to their server.
1.6. Add app to a Discord Server#
To add your bot to your own discord server, open a new browser tab and copy the link in to the url bar. Then you will have an option to add your bot to any servers you own.
Note: After adding app to server, there is a confirmation page about the permissions. “Authorize” your bot.
1.7. Get Channel Id Number#
One additional piece of information you might need for your bot is the channel ID for a channel in a discord server. In order to get a channel ID, open your settings menu.
Then enable developer mode in the advanced settings.
Once developer mode is on, you can get a channel ID by right-clicking on a channel.
Save the channel ID somewhere so you can have your bot reference it later (e.g., post to that channel).
1.8. Test your tokens#
Now that you have your token, and other info, you can test out your code in chapter 2.3.8 (Demo: Try Running the Discord Bot!). You can try running the code and replacing the fake discord token and channel ids with the ones from your account, and see if you can use the code to make an actual post to your account.
1.9. Understand Discord Rules for Bots#
Before you try doing anything too creative with Discord bots, make sure you look over the Discord Developer Policy, that way you don’t get yourself banned.