A fully functional discord.js TypeScript bot template, with Slash & Regular text commands and events handlers.
Before doing anything else, it is important to complete this step before, and it is the __config.json
file creation.
To begin, create a folder called data
in your root directory, inside that data
folder, create another folder called json
, inside it, create the __config.json
file, and finally put inside it these informations:
{
"client_id": "YOUR_CLIENT_ID",
"_token": "YOUR_BOT_TOKEN",
"_dbKey": "YOUR_MONGODB_KEY",
"_defaultPrefix": ">>",
"guilds": {
"main": "YOUR_MAIN_GUILD_ID",
"authorized": []
}
}
{
"dependencies": {
"discord.js": "^14.14.1",
"fs": "^0.0.1-security",
"mongoose": "^8.2.3",
"pretty-ms": "^7.0.1"
}
}
To install these libraries run in your terminal the following command:
npm install
You also need to install development dependencies:
{
"devDependencies": {
"@types/node": "^20.11.30",
"tsx": "^4.7.1"
}
}
To do so, run the following command:
npm install -D tsx @types/node
Globally install TypeScript:
npm install -g typescript
To run your TypeScript code, it is required to run the tsx watch src/index.ts
command, whom alias is npm run dev
.
npm run dev
However, it is not recommended to run your TypeScript code primarily due to performance issues. You will have to compile the TypeScript files to JavaScript files, in an automatically created dist
folder.
- To compile the TypeScript files to Javascript files, run the following command:
npm run build
- And finally, to run your compiled JavaScript files, run the follow command:
or
npm run start
node .