ns Docsns Docs
Getting Started

Configuration

Configure environment variables and core metadata for the bot

Setting Up Configuration

In this section, we will set up all required configuration files for the bot.
A proper configuration layer keeps sensitive values secure, improves type safety, and makes the project easier to maintain as it grows.


Project Structure

Create a configs directory inside the src folder. This directory will contain all configuration-related files used across the application.

If you run the PowerShell command from the previous step, this folder should already exist.

Inside src/configs, create the following files:

  • botConfig.ts – Handles environment-based configuration
  • metadata.ts – Stores static bot metadata such as name and prefix
botConfig.ts
metadata.ts

Environment Variable Configuration (.env)

Environment variables should not be accessed directly throughout the codebase. Instead, we load and validate them through a dedicated configuration file.

Using a config file provides stronger type safety, centralized control, and cleaner imports. This is a recommended practice when working with TypeScript.

Never commit your .env file to version control. Always add it to .gitignore.

botConfig.ts

Add the following implementation to src/configs/botConfig.ts:

import dotenv from 'dotenv'

dotenv.config()

interface BotConfig {
  BOT_TOKEN: string
  BOT_ID: string
  SERVER_ID: string
  DEVELOPER_IDS: string[]
  ERROR_CHANNEL: string
  GATE_CHANNEL: string
  WELCOME_CHANNEL: string
}

const config: BotConfig = {
  BOT_TOKEN: process.env.AUTH_TOKEN as string,
  BOT_ID: process.env.CLIENT_ID as string,
  SERVER_ID: process.env.SERVER_ID as string,
  DEVELOPER_IDS: (process.env.DEVELOPER_IDS || '').split(','),
  ERROR_CHANNEL: process.env.ERROR_CHANNEL_ID as string,
  GATE_CHANNEL: process.env.JOIN_GATE_CHANNEL_ID as string,
  WELCOME_CHANNEL: process.env.WELCOME_GATE_CHANNEL_ID as string,
}

export default config

This file:

  • Loads environment variables using dotenv
  • Enforces strict typing via an interface
  • Exposes a single, reusable configuration object

Application Metadata

Metadata such as the bot name and prefix should be stored separately from environment variables. These values are not sensitive and are often reused in multiple places.

metadata.ts

Create src/configs/metadata.ts and add the following:

export const BOT = {
  PREFIX: 'your-prefix-here',
  NAME: 'your-bot-name-here',
}

This file can be extended later to include additional metadata such as version, author name, or support links.


Summary

At this point, you have:

  • Centralized all environment variables
  • Enforced type safety for configuration values
  • Separated runtime configuration from static metadata

Your project is now properly configured and ready to move on to the next setup step.

Last updated on

On this page