Discord Bot Template
This template provides a basic setup for creating a Discord bot using discord.js.
Features
discord.js: The official Node.js module for interacting with the Discord API.dotenv: For loading environment variables from a.envfile.nodemon: Automatically restarts the bot when file changes are detected during development.- Basic Command Handler: A simple structure to handle Discord slash commands.
Files Included
src/index.js: The main entry point for your bot. It initializes the Discord client, loads commands, and handles interactions.src/config.json: (You'll need to create this) Contains your bot's token and other configuration.src/commands/: A directory to store your bot's slash command files..env.example: An example environment file. Rename this to.envand fill in your Discord bot token..gitignore: Configured to ignorenode_modules,.env, and other common files.package.json: Configured withstartanddevscripts, and necessary dependencies.
Available Scripts
In the project directory, you can run:
npm start: Runs the bot in production mode.npm run dev: Runs the bot in development mode usingnodemonfor automatic restarts.
Getting Started
- Install Dependencies: After creating your project, install the dependencies:
npm install - Configure Your Bot: Create a
config.jsonfile in thesrcdirectory with your bot's token:Alternatively, rename{
"token": "YOUR_DISCORD_BOT_TOKEN"
}.env.exampleto.envand addDISCORD_TOKEN=YOUR_DISCORD_BOT_TOKEN. - Create Commands: Add your slash command files to the
src/commands/directory. - Run the Bot: Start your bot using
npm startornpm run dev.