Skip to main content
Version: v2.10.1

Configuration filesโ€‹

tip

This page follows the official discordjs.guide .

Once you add your bot to a server , the next step is to start coding and get it online. Let's start by creating a config file for your client token and a main file for your bot application.

As explained in the "What is a token, anyway?" section, your token is essentially your bot's password and you should protect it as best as possible. This can be done through a config.js file or by using environment variables.

Open your application in the Discord Developer Portal and go to the Bot page to copy your token.


Using config.jsโ€‹

Storing data in a config.js file is a common way of keeping your sensitive values safe. Create a config.js file in your project directory and paste in your token. You can access your token inside other files using require().

module.exports = {
token: "[TOKEN]", // required
prefix: "!", // optional
nodes: [
{
host: "[IP_ADDRESS]", // required
port: 9999, // optional but recommended! Defaults to 443
password: "[PASSWORD]", // optional but recommended!
useSSL: false, // optional
maxRetryAttempts: 500, // optional
retryDelayMs: 300000, // optional
enableSessionResumeOption: true, // optional
sessionTimeoutSeconds: 300, // optional
},
],
};

Using dotenvโ€‹

Another common approach is storing these values in a .env file. Each line should hold a KEY=value pair.

Install the dotenv package :

npm install dotenv
warning

dotenv does not natively support arrays. Store your node config as a JSON string and parse it at runtime, as shown below.

TOKEN=""
PREFIX=""
LAVALINK_NODES=[{"host":"","port":9999,"password":"","useSSL":false,"maxRetryAttempts":500,"retryDelayMs":300000,"enableSessionResumeOption":true,"sessionTimeoutSeconds":300}]

Resulting codeโ€‹

You can review the complete example on the GitHub repository here .