A progressive Node.js framework for building efficient and scalable Discord.js applications.
Cordwork is a framework for building Discord bots like NestJS. It will help make the project more cohesive and massive.
$ npm install @cordwork/core
...
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
...
import { CordWork } from '@cordwork/core';
import { App } from './app.module';
async function bootstrap() {
const client = await new CordWork()
.SetToken(process.env.BOT_TOKEN || '')
.AttachApp(App)
.Launch();
}
bootstrap();
- To check out the example.
Cordwork is a collection of modules. The program starts from the top-level module. Can add modules to modules.
import { Module } from '@cordwork/core';
@Module({
imports?: Type<any>[],
events?: Type<any>[],
commands?: Type<any>[],
guilds?: Guild[],
components?: Type<any>[],
extensions?: Type<any>[],
})
export class App {
}
Controller is an object that manages message components(Button, Slect Menus, etc...), event handlers, and slash commands.
import { DiscordCommand } from '@coredwork/core';
@DiscordCommand({
name: 'ping',
description: 'The test command.',
guilds: ['my guild name'],
})
export class CommandController {
async listener(interaction): Promise<void> {
interaction.reply('Pong!');
}
import { Inject, DiscordEvent, CordWorkClient } from '@cordwork/core';
@DiscordEvent('ready')
export class ReadyController {
constructor(
@Inject(CordWorkClient) private client: CordWorkClient
) {}
async listener(): Promise<void> {
console.log(`Logged in as ${this.client?.user?.tag}!`);
const application = this.client.application;
if ( application ) {
console.log('client id', application.id);
}
}
}
import { MessageButton } from 'discord.js';
import { Inject, DiscordComponent, CordWorkClient } from '@cordwork/core';
@DiscordComponent()
export class ComponentClass {
constructor(
@Inject(CordWorkClient) private client: CordWorkClient,
) {}
create(): MessageButton {
return new MessageButton()
.setCustomId('mybutton')
.setLabel(`LABEL ${this.client?.user?.tag}`)
.setStyle('PRIMARY');
}
listener(interaction): void {
interaction.reply('button click');
}
}