Introduction
This module is an extension of discord.js, so the internal behavior (methods, properties, ...) is the same.
This library allows you to use TypeScript decorators on discord.js, it simplify your code and improve the readability !
Requirements
Name | Version |
---|---|
Node.js | >= 16.6.0 |
TypeScript | >= 4.4.4 |
Easy setup - starter project
- Setup new project
npx create-discordx
- Build
- npm
- Yarn
npm run build
yarn build
- Setup bot token
- Windows
- Linux
// cmd
set BOT_TOKEN=REPLACE_THIS_WITH_YOUR_BOT_TOKEN
// powershell
$ENV:BOT_TOKEN="REPLACE_THIS_WITH_YOUR_BOT_TOKEN"
export BOT_TOKEN=REPLACE_THIS_WITH_YOUR_BOT_TOKEN
- Run
- npm
- Yarn
npm run start
yarn start
- And you're done, everything has been done for you! 🚀
Installation
- Stable
- Development
Use npm or yarn to install discordx with discord.js
- npm
- Yarn
npm install discordx discord.js
yarn add discordx discord.js
Install your TypeScript dev dependencies too
- npm
- Yarn
npm install --save-dev @types/node typescript
yarn add --dev @types/node typescript
And you should see this in your package.json
{
// ...
"dependencies": {
"discordx": "^X.X.X",
"discord.js": "^X.X.X"
},
"devDependencies": {
"@types/node": "^X.X.X",
"typescript": "^X.X.X"
}
// ...
}
If you need to update again in the future just run:
- npm
- Yarn
npm install discordx discord.js
yarn add discordx discord.js
Use npm or yarn to install discordx with discord.js
- npm
- Yarn
npm install discordx@dev discord.js@dev
yarn add discordx@dev discord.js@dev
Install your TypeScript dev dependencies too
- npm
- Yarn
npm install --save-dev @types/node typescript
yarn add --dev @types/node typescript
And you should see this in your package.json
{
// ...
"dependencies": {
"discordx": "^X.X.X-dev.###",
"discord.js": "^X.X.X-dev.###.###"
},
"devDependencies": {
"@types/node": "^X.X.X",
"typescript": "^X.X.X"
}
// ...
}
If you need to update again in the future just run:
- npm
- Yarn
npm install discordx@dev discord.js@dev
yarn add discordx@dev discord.js@dev
Execution environment
To start your bot you can compile your code into JavaScript with TypeScript using the tsc
command or simple use ts-node.
You must specify the .js files when you initialize your client if you compile your code into JavaScript with tsc
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers,
],
silent: false,
});
client.on("ready", async () => {
console.log(">> Bot started");
// to create/update/delete discord application commands
await client.initApplicationCommands();
});
client.login(BOT_TOKEN);
:::
tsconfig.json
Your tsconfig.json file should look like this:
- ECMAScript
- CommonJs
{
...
"type": "module",
...
}
{
"compilerOptions": {
"module": "ESNext", // required
"target": "ESNext", // required
"noImplicitAny": true,
"sourceMap": true,
"strict": true,
"outDir": "build",
"emitDecoratorMetadata": false, // required
"experimentalDecorators": true, // required
"declaration": false,
"importHelpers": true, // required
"forceConsistentCasingInFileNames": true,
"moduleResolution": "Node", // required
"esModuleInterop": true // required
},
"exclude": ["node_modules"]
}
{
...
"type": "commonjs",
...
}
{
"compilerOptions": {
"module": "CommonJS", // required
"target": "ESNext", // required
"noImplicitAny": true,
"sourceMap": true,
"strict": true,
"outDir": "build",
"emitDecoratorMetadata": false, // required
"experimentalDecorators": true, // required
"declaration": false,
"importHelpers": true, // required
"forceConsistentCasingInFileNames": true,
"moduleResolution": "Node", // required
"esModuleInterop": true // required
},
"exclude": ["node_modules"]
}
Need help?
You can also find help with examples folder