# @cordwork/core

> A beautiful Discord bot framework.

Latest version **1.1.12** (published 2022-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cordwork/core
pnpm add @cordwork/core
yarn add @cordwork/core
bun add @cordwork/core
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.12 |
| Published | 2022-08-08 |
| First published | 2022-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 80.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 6 |
| Author | raravel |
| Maintainers | tree-some |
| Keywords | discord, api, bot, client, node, discordapp |

## Links

- npm: https://www.npmjs.com/package/@cordwork/core
- Repository: https://github.com/cordwork/core
- Homepage: https://github.com/cordwork/core#readme
- Issues: https://github.com/cordwork/core/issues
- npm.io page: https://npm.io/package/@cordwork/core

## Dependencies (5)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [tslog](https://npm.io/package/tslog.md) ^3.3.3
- [discord.js](https://npm.io/package/discord.js.md) ^14.1.2
- [@discordjs/rest](https://npm.io/package/@discordjs/rest.md) ^0.5.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.1.12 (latest) — 2022-08-08
- 1.1.11 — 2022-08-08
- 1.1.10 — 2022-08-08
- 1.1.9 — 2022-08-03
- 1.1.8 — 2022-08-03
- 1.1.7 — 2022-08-03
- 1.1.6 — 2022-08-03
- 1.1.5 — 2022-08-02
- 1.1.4 — 2022-07-27
- 1.1.3 — 2022-07-27
- 1.1.2 — 2022-07-27
- 1.1.1 — 2022-07-27
- 1.1.0 — 2022-07-27
- 1.0.1 — 2022-07-08
- 1.0.0 — 2022-07-08

## README

<p align="center">
  <img src="https://avatars.githubusercontent.com/u/108444461" width="120" alt="Cordwork Logo" />
</p>

<p align="center">
  A progressive <a href="https://nodejs.org/">Node.js</a> framework for building efficient and scalable <a href="https://discord.js.org/">Discord.js</a> applications.
</p>


## Description

Cordwork is a framework for building Discord bots like [NestJS](https://nestjs.com/). It will help make the project more cohesive and massive.


## Getting Started

### Install
```
$ npm install @cordwork/core
```

### tsconfig.json
```json
...
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
...
```

### main.ts
```typescript
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](/examples/).


## Module

Cordwork is a collection of modules. The program starts from the top-level module. Can add modules to modules.

### app.module.ts

```typescript
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

Controller is an object that manages message components([Button](https://discordjs.guide/interactions/buttons.html), [Slect Menus](https://discordjs.guide/interactions/select-menus.html), etc...), [event handlers](https://discordjs.guide/creating-your-bot/event-handling.html), and [slash commands](https://discordjs.guide/interactions/slash-commands.html).

### Slash Commands
```typescript
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!');
  
}
```

### Event Handler
```typescript
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);
    }
  }
}
```

### Message Component

```typescript
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');
  }
}
```

---
_Source: https://npm.io/package/@cordwork/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
