This package has been deprecated

Author message:

This module is deprecated in favour of nest-bots

nestcord
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Nest Logo

Description

A Nest framework to run your Discord bot.

Usage

Command System

Creating a command

// test.command.ts

@Command.Name('test')
@Command.Alias('t', 'tt')
export class TestCommand implements CommandHandler {

  async handle(client: Client, args: string[], msg: Message): Promise<void> {
    // do something
  }

}

Defining a parent command

//test.123.command.ts

@Command.Name('123')
@Command.Parent(TestCommand)
export class Test123Command implements CommandHandler {

  async handle(client: Client, args: string[], msg: Message): Promise<void> {
    await msg.reply('123');
  }

}

All commands and events have to be registered as providers

Using the command system

By default NestCord comes without a command handler. To use the default handler you can just add NestcordCommandHandler to your providers, along with your commands..

The prefix can be set using NestcordCommandHandler.prefix.

Event System

@Event.Handler('ready')
export class TestEvent implements EventHandler {

  constructor(@InjectClient() private readonly client: Client) {}

  private logger: Logger = new Logger('ReadyLogger');

  async handle(): Promise<void> {
    this.logger.log(`Logged in as ${this.client.user.tag}`);
  }

}

All commands and events have to be registered as providers

Single Instance

Import Nestcord somewhere in your modules

@Module({
  imports: [
    NestcordModule.forRoot('YOUR_BOT_TOKEN'),
  ],
})
export class AppModule {}

Sharded Instance

WARNING: Sharding is an experimental feature that is working by forking multiple instances of NestJS, use with caution!

Creating a launcher

// launcher.ts

NestFactory.createApplicationContext(LauncherModule, {
  logger: ShardLogger.create(process.env.SHARD_ID),
});

This example is using a custom logger, to distinguish the logged messages.

// launcher.module.ts

@Module({
  imports: [NestcordModule.forShard()],
  providers: [],
})
export class LauncherModule {}

Using the launcher

@Module({
  providers: [/* Your Commands and Events */],
  imports: [ShardcordModule.forRoot(
    require.resolve('./launcher'),
    {
      token: 'YOUR_BOT_TOKEN',
      totalShards: 4,
    },
  ],
})
export class AppModule {}

To use the shard all commands/events have to be registered in the shard's context

This documentation needs to be improved a lot...

Credits

  • Author - LambdaXCF
  • The one who can actually type - Sascha_T

License

NestCord is MIT licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i nestcord

Weekly Downloads

1

Version

0.0.4

License

MIT

Unpacked Size

58.2 kB

Total Files

50

Last publish

Collaborators

  • lambdaxcf