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 (not limited to):
- Prerequistite Script to ensure all .env values are properly filled
- Command & Event handlers
- Starter Slash & Context-Menu Commands
- Optional per-command cooldowns & User / Client permission checking
-
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. APPLICATION_ID= # Your bot's application ID (can be found on Discord or on the Discord Developer Portal)
-
Installing dependencies
pnpm install
-
Deploying Commands
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
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