This sample Discord bot written in TypeScript is a great starting place for creating the bot of your ✨ dreams ✨.
Primarily using discord.js with examples used from the discord.js guide.
Features include (but not limited to):
- Command & Event handlers
- Starter Slash & Context-Menu Commands
- Optional per-command cooldowns & User / Client permission checking
Important
Most current Node LTS (Long-Term Support) Version is required
-
Clone the repository here on Github or from terminal (shown below)
git clone https://github.com/joeyk710/sample-discordjs-bot.git cd sample-discordjs-bot
-
Rename .env.example to
.env
-
Open the .env file and fill in the required values as shown below
DISCORD_TOKEN= # Your bot token GUILD_ID= # Only put an ID here if you want commands to be registered in one server. CLIENT_ID= # Your bot's application ID (can be found on Discord or on the Discord Developer Portal)
-
Installing dependencies
npm install yarn install pnpm install
-
Deploying Commands
npm run deploy yarn run deploy pnpm run deploy
Note
If there is no GUILD_ID
in the .env file, commands will be registered globally.
Only run this terminal script if you need to add commands or edit command data that do not appear in your server.
-
Starting the bot
npm run start yarn run start pnpm run start
Name | Description |
---|---|
/ping | Responds with "Pong!" |
Echo | Echoes the message selected in the channel the command was sent in |
Note
Please check the discord.js docs, discord.js guide, and discord-api-types for proper types, properties and method usage.
You will notice the current discord.js guide uses @discordjs/builders
for command creation. This template uses raw objects for creating commands which makes use of enum types ApplicationCommandType and ApplicationCommandOptionType.
If you have any problems, please don't hesitate to open an issue here.
Contributions are welcome! Please don't hesitate to open a pull request here.
This project is licensed under the GNU General Public License v3.0
- see the LICENSE.md file for details