Skip to main content

🔑 Discord Bot Credentials

For your Discord Bot to work, you need to set up a few environment variables to authenticate with Discord.

These are secret values that you should never share with anyone. They're stored in a .env file, which is automatically loaded by Robo.js when you start your project.

What You Need

Get the following environment variables from the Discord Developer Portal.

Client ID

This is your Discord Application ID, found in the Discord Developer Portal. Sign in with your Discord account, click on your bot application, and find the Application ID in the General Information tab.

Discord Application ID

In your .env file, add the following line:

.env
DISCORD_CLIENT_ID="your_application_id"
Reminder

Don't forget to replace your_application_id with the value you just obtained!

Discord Bot Token

This is your Discord Bot Token, found in the Bot tab of your app under the Token section near the top. You may need to reveal it by clicking Reset Token.

Discord Bot Token

In your .env file, add the following line:

.env
DISCORD_TOKEN="your_bot_token"

Optional Variables

The environment variables below are not strictly necessary, but they're sure to make your life easier during development and testing.

DISCORD_GUILD_ID

Setting up a DISCORD_GUILD_ID environment variable is a neat trick for testing. It ensures that any new commands you create only get applied to the Discord server this ID belongs to. To learn more about setting up test Discord servers, check out our previous documentation. To get the DISCORD_GUILD_ID, follow these steps:

  1. Open Discord and navigate to the server you want to use.
  2. Right-click the server icon and click "Copy ID."

In your .env file, add the following line:

.env
DISCORD_GUILD_ID={your_guild_id}

Replace {your_guild_id} with the value you just obtained.

DISCORD_DEBUG_CHANNEL_ID

The DISCORD_DEBUG_CHANNEL_ID environment variable is useful for directing errors to a specific channel during development. This helps developers focus on the task at hand and handle async errors that may occur during development and are out of their control. To get the DISCORD_DEBUG_CHANNEL_ID, follow these steps:

  1. Enable Developer Mode in Discord by going to User Settings > Advanced > Developer Mode.
  2. Navigate to the channel you want to use as your debug channel.
  3. Right-click the channel and click "Copy ID."

In your .env file, add the following line:

.env
DISCORD_DEBUG_CHANNEL_ID={your_debug_channel_id}

Remember to replace {your_debug_channel_id} with the value you just obtained.

🚨 Note

Using DISCORD_DEBUG_CHANNEL_ID is not strictly necessary, and we gently discourage its use. You shouldn't just shove errors away in a place where you can ignore them. Instead, check out the Debugging Documentation to learn how to handle errors effectively.

Enabling Developer Mode in Discord

Enabling Developer Mode in Discord allows you to access handy features, like copying IDs for servers, channels, and users. To enable Developer Mode, follow these simple steps:

  1. Open Discord.
  2. Click on the gear icon in the lower-left corner to open your User Settings.
  3. In the left sidebar, scroll down and click on "Advanced."
  4. Toggle on the "Developer Mode" switch.

That's it! You now have Developer Mode enabled, unlocking a world of possibilities for your bot development journey. 🚀

Keep It Secure

Make sure to keep your .env file safe and never share it with anyone. If you accidentally expose your credentials, you can regenerate them in the Discord Developer Portal.

Remember to add .env to your .gitignore file to prevent it from being pushed to your repository.

.gitignore
.env

Don't worry, Robo.js will automatically load your environment variables when you start your project.

Robo.js Logo

MIT © 2024 Robo.js By WavePlay