Experimental Discord bot written in Python
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

setup.md 6.3KB

Setup

Make Discord application

A Discord application is the record in Discord’s servers about your bot. An application can be a lot of things, not just bots, but we only care about bots. You can think of it sort of like the bot’s Discord account but with more nerdy settings. When you run the bot script, it will authenticate as this application and assume the identify of the bot user in Discord. Authentication is done via a client token, discussed more later.

Rocketsoup is currently running the bot under an application entry he created under his own account, and running the bot script in a terminal on his own computer. Professional! If someone will be taking over the bot, they’ll likely want to create their own application under their own account (or a shared account perhaps).

The application portal can be found here: https://discord.com/developers/applications Click “New Application” and give it a name, e.g. Rocketbot. Then click into it to see its settings. It’s been a while since I set this up, and things are always changing, but settings of note:

  • General Information > App Icon - You can use this or some other 1024x1024 image: icon.png. This is what shows up when inviting the bot to a server.
  • General Information > Application ID - Take note of this. You’ll need it later.
  • Installation > Installation Contexts - Enable “Guild Install”, disable “User Install”
  • Bot > Icon - Same image as the App Icon above. This is what actually shows as the bot’s avatar in Discord.
  • Bot > Username - What the bot shows up as in Discord.
  • Bot > Token - ⚠️ IMPORTANT. This is the client token to authenticate the bot. It needs to be filled in the config. You will only be shown the value ONCE!! So store it somewhere safe, like a password manager! If you lose it you can create a new one. More below on what to do with this value.
  • Bot > Privileged Gateway Intents - These give the bot broad categories of privileges for certain kinds of data. Since Rocketbot is pretty broad in its functionality, it needs a lot. Enable:
    • Presence Intent - For tracking joins/leaves, I think
    • Server Members Intent - For getting member info
    • Message Content Intent - To be able to get the text and other details about messages

[!TIP] It can be useful to set up a second application specifically for testing. e.g. I have a “Rocketbot Test” application, configured exactly the same as the production application, but it can be in a completely independent list of servers for testing and can run at the same time as the production one.

Configure bot script

The bot relies on config.py for its general configuration. (Settings for each individual guild are stored elsewhere; more on that later.) You’ll want to rename or copy config.sample.py to config.py and open it in an editor. The file consists of a single CONFIG dict.

The most essential value to set is CONFIG.client_token. The client token you got above in the Discord application portal that you definitely stored in a safe place like I told you is what you want to paste here.

You may also want to set CONFIG.config_path. In retrospect, that’s confusing naming. Anyway, it’s the path to a directory where guild-specific settings will be stored. It can be wherever makes sense to you. I just store em in a config subdirectory in the project itself. That’s probably a bad idea for reasons I’m too bad a programmer to know about. Store ‘em wherever you want. (These guild setting files are a good candidate for timely backups, btw, if that influences your choice. Maybe a synced cloud folder?)

Run the script

I wrote this for Python 3.9, and its only dependency is the Discord.py library. I am bad at Python, so use these instructions only until a grown up programmer can be found to give you better ones. I’m on Mac, so apologies for any inadvertent Mac-specificness. Linux will be similar. Windows probably won’t be as similar.

  1. Set up a virtual environment and install dependencies (only need to do this once) shell python3.9 -m venv .venv source .venv/bin/activate pip install -r requirements.txt
  2. Run the bot shell source .venv/bin/activate # skip if you already just did it above python main.py

It will take a few seconds to connect and set itself up, and when you see output like this it means it’s ready and listening for things to happen.

[2025-12-11T16:30:52|GeneralCog|-] Connected
[2025-12-11T16:30:54|GeneralCog|-] Bot done initializing
----------------------------------------------------------

Leave it running and, I dunno, minimize the window or something. You can see events logged here as they come up. If you wanna stop the bot, just hit ctrl+C.

Invite bot to your server

You can invite the bot to your server by constructing a link like so:

https://discord.com/oauth2/authorize?client_id=APPIDHERE&scope=bot&permissions=4290289506188502

The APPIDHERE is the value in the application portal under General Information > Application ID. ⚠️IMPORTANT: It is NOT your client token. That’s a secret; your application ID isn’t. It’s an 18-digit number, give or take. That URL can be used by anyone to invite the bot to their server. It will prompt you for which server to invite it to and ask you if you want to grant it a bunch of server permissions. Give it everything it asks for. It’ll probably be fine.

[!NOTE] The other big multidigit number in that URL is the permissions mask, and it affects what checkboxes appear in that invite screen. That number is determined using the calculator in the application dashboard at the bottom of the Bot section. While I started out being more selective in only requesting the permissions I knew I needed, I kept bumping into access errors for one thing or another. So now I’m just like gimme damn near everything unless I know for sure I don’t need it.

Configure bot for your server

You can verify the bot is working by typing /hello in chat on that server and it should reply to you.

The bot has a number of “cogs” (a term the Discord.py library uses) for distinct bits of functionality with their own commands and subcommands. E.g. the thingy that detects join raids is its own cog. They’re all disabled by default, so you’ll want to enable whichever ones suit you.

More details in [Commands][commands.md].