Getting Started

This guide will help you get started with SudoBot. You will learn how to build the bot from source, configure and run it on your own server, so that it does exactly what you want.

Info

If you don't want to set the bot up yourself and want a pre-hosted solution for free, you can contact @rakinar2 at Discord.

Prerequisites

Before you start, you need to have the following installed on your system:

  • A Discord API Application token (bot token). Go to the Discord Developer Portal to create a new application, and get the token.
  • A PostgreSQL database server. You can use a local server or use a cloud service like Supabase.

Additionally, you can also set these up if you want to use them:

  • Cat and dog API Token, for fetching cat and dog images using cat and dog commands, the tokens can be obtained at thecatapi.com and thedogapi.com.
  • Pixabay API Token to use the pixabay command. See Pixabay's API Docs for more information.
  • A Discord Webhook URL for sending error reports.
  • Node.js (v21 or higher) or Bun (v1.1.12 or higher). These will be installed automatically if you don't install them, during the build process.
  • Git (optional; to clone the repository)

Lastly, we expect you to have a very basic understanding of how to use a terminal or command prompt, and how to run commands.

Installation

To install SudoBot, you need to clone the repository first, if you have Git installed. Run the following command in your terminal:

git clone https://github.com/onesoft-sudo/sudobot

If you don't have Git installed, you can download the repository as a zipball/tarball from the GitHub Releases Page. Then, extract the downloaded file to a directory of your choice.

Next, navigate to the directory where you have cloned the repository using Git, or extracted the zipball/tarball, by running the following command in your terminal:

cd sudobot

Now, to build the project, we'll use BlazeBuild, which is a blazingly fast build tool, for TypeScript and JavaScript projects. To use BlazeBuild, you don't need to install anything including BlazeBuild itself, as it will be installed and set-up automatically during the build process. BlazeBuild will also make sure to install any missing SDKs or tools required for building the project.

The repository already contains the BlazeBuild wrapper (blazew). To build the project, run the following command in your terminal:

./blazew build

This will build, compile and package the project into a build directory in the project root, which contains the compiled JavaScript files. Depending on your system, the build process may take a few seconds to a few minutes to complete. We recommend using a system with at least 8GB of RAM and 2 CPU cores for faster build times.

If you don't have enough resources, this command will fail with heap allocation errors. If that happens, or if you don't want to build it yourself, don't worry. You can download prebuilt versions for every release. The builds are tested on Node.js v21, however they should also work with v20. You might see that only Linux and macOS (darwin) releases are available. This doesn't mean you cannot run the bot on Windows systems - only the native bindings are platform dependent. You don't need to worry about that in most cases and the bot will just work fine. You can download the prebuilt versions in the GitHub releases page: https://github.com/onesoft-sudo/sudobot/releases/latest

As always if you ever encounter errors with commands or you see something is not working as you expect, you can join our Discord Server and ask for help!

Configuration

After building the project, you need to configure the bot to run on your server. You'll need to configure the following:

  • The environment variables
  • The configuration files

Environment Variables

The bot uses environment variables for storing secret credentials like your bot's token. You can set these in a .env file in the project root.

Create a new file named .env in the project root, and add the following environment variables:

# Your bot's token from the Discord Developer Portal.
TOKEN=your-bot-token

# Client ID of your bot from the Discord Developer Portal.
CLIENT_ID=your-bot-client-id

# Client Secret of your bot from the Discord Developer Portal.
CLIENT_SECRET=your-bot-client-secret

# The ID of the guild where you want to register the commands,
# during development mode, and where the bot will send error reports.
# The bot will also search for emojis in this guild.
HOME_GUILD_ID=your-home-guild-id

# Your PostgreSQL database connection URL.
# Sometimes your database provider might provide a connection URL 
# exactly in this format. Otherwise if they give you the details
# separately, you can format it to look like this.
DB_URL=postgresql://username:password@hostname:port/database

# JWT Secret for generating JWT tokens.
# On systems with openssl installed, you can generate a random 
# secret using the following command:
#
#    openssl rand -base64 32
#
# Replace `your-jwt-secret` with the generated secret.
JWT_SECRET=your-jwt-secret

# Optionally, you can uncomment the following to turn on debug mode 
# to see more detailed logs, and enable certain development features.

# NODE_ENV=development

There are a lot of other environment variables that you can set, but these are the most important ones. You can check out all the environment variables in the environment variable schema file.

Configuration Files

The bot uses configuration files for storing settings like the bot's prefix, the system administrator IDs, and more. Some of these settings are guild-wide, and some are global. The guild-wide configuration file is config.json, and the global system-level configuration file is system.json. The files are located at config/ in the project root. These configuration files don't contain any specific setting, they are just a starting point for you to configure the bot. You can edit these files to your liking.

To see all the possible configuration options, please refer to these schema files:

Setting up the Database

The bot uses a PostgreSQL database to store data like guild settings, user settings, and more.

To set up the database, make sure you've set the DB_URL environment variable in the .env file. Then, run the following command in your terminal to run the database migrations:

./blazew migrate

This will create the required tables in the database.

Running the Bot

After configuring the bot, you can run it using the following command:

./blazew run

By default, BlazeBuild will use Bun to run the bot. If you want to use Node.js instead, you can run the following command:

./blazew run -- --node

This will start the bot, and you should see the bot online in your Discord server. Congratulations! You have successfully set up a custom instance of SudoBot on your server 🎉

Next steps

Registering application commands

The bot uses Discord's Application Commands for slash commands and context menus. To register the application commands to the Discord API, you can run the following command:

./blazew run -- -- -u

If you have debug mode enabled and have HOME_GUILD_ID set in the .env file, the bot will register the commands in the development guild. If you don't have debug mode enabled, the bot will register the commands globally.

If you want to force the bot to register the commands globally, you can run the following command:

./blazew run -- -- -u -g

To clear the registered commands, you can run the following command:

./blazew run -- -- -c

Once again, if you have debug mode enabled, the bot will clear the commands in the development guild. Otherwise, it will clear the commands globally. To force the bot to clear the commands globally, you can run the following command:

./blazew run -- -- -c -g

Emojis

The bot uses some custom emojis and it will try to find those emojis in the Home Guild (The main server, which is configured in HOME_GUILD_ID environment variable).

The emojis are freely available for download at the download server. The bot uses some other emojis as well, if you want you can download them from emoji.gg.

If you don't add these emojis, the bot may send messages that look unformatted or broken.

Help & Support

In case if you're facing issues, feel free to open an issue at GitHub. Or you can contact the Author of the bot in the following ways:

Give the repository a star to show your support! We'll be really thankful if you do.