create-discord-express-bot
v1.0.1
Published
Scaffold a Discord + Express bot template.
Downloads
33
Readme
Discord + Express Bot Template
A ready-to-publish npm package template for a Discord bot that also runs an Express web server. Built for Node 18+ and Discord.js v14.
Features
- Slash-command framework with auto-loader (
/pingincluded) - Express server with health and root routes
.envsupport with safe defaults- Graceful shutdown
- Dev workflow with
nodemon - Command registration script (guild-scoped for fast iteration)
Prerequisites
- Node.js 18.17+ (required for Discord.js v14)
- npm 9+ (comes with Node)
- A Discord application and bot token (guide)
Creating a Discord bot
- Create a new application at https://discord.com/developers/applications
- Add a bot user under the Bot tab
- Copy the Bot Token into your
.env - Copy the Application (Client) ID into your
.env - Get your Guild ID by enabling Developer Mode in Discord → right click your server → "Copy Server ID"
Quick start
- Clone & install
npm install- Configure environment
Copy
.env.exampleto.envand fill in your values:
DISCORD_TOKEN=your-bot-token
DISCORD_CLIENT_ID=your-application-client-id
DISCORD_GUILD_ID=your-dev-guild-id
PORT=3000
NODE_ENV=development- Register commands (guild)
npm run register:commands- Run the bot + server
npm run dev
# or
npm startVisit http://localhost:3000 to see the web server.
Project structure
.
├── scripts/
│ └── register-commands.js
├── src/
│ ├── bot.js
│ ├── commands/
│ │ └── ping.js
│ ├── index.js
│ └── server.js
├── .env.example
├── .gitignore
├── package.json
└── README.mdDeploy notes
- Update
register-commands.jsto use global commands once stable (can take up to 1h to propagate). - Keep your token secret. Never commit
.env. - Add process manager (e.g. PM2) or containerize for production. A simple Dockerfile is included.
License
MIT
