# discord-decorators

> Create your discord bot by using TypeScript and decorators!

Latest version **5.0.10** (published 2021-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install discord-decorators
pnpm add discord-decorators
yarn add discord-decorators
bun add discord-decorators
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.10 |
| Published | 2021-05-26 |
| First published | 2021-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 123.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 324 |
| Author | Owen Calvin |
| Maintainers | owencalvin |
| Keywords | typescript, discord, bot, client, api, library, framework, tool, decorators |

## Links

- npm: https://www.npmjs.com/package/discord-decorators
- Repository: https://github.com/OwenCalvin/discord.ts
- Homepage: https://github.com/OwenCalvin/discord.ts#readme
- Issues: https://github.com/OwenCalvin/discord.ts/issue
- npm.io page: https://npm.io/package/discord-decorators

## Dependencies (3)

- [glob](https://npm.io/package/glob.md) ^7.1.7
- [discord.js](https://npm.io/package/discord.js.md) github:discordjs/discord.js
- [discord-api-types](https://npm.io/package/discord-api-types.md) ^0.18.1

## 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

- 5.0.10 (latest) — 2021-05-26

## README

<p align="center">
  <br/>
  <img src="https://i.imgur.com/kSLOEIF.png" width="150px">
  <br/>
  <br/>
  <h1 align="center">
    <p  align="center">
      discord.ts (@typeit/discord)
    </p>
  </h1>
    <p align="center">
      <b>
        Create your discord bot by using TypeScript and decorators!  
      </b>
    <p>
  </p>
  <br/>
</p>

# 🎻 Introduction
This module is an extension of **[discord.**js**](https://discordjs.guide/)**, 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 !

# 📜 Documentation
**[https://owencalvin.github.io/discord.ts/](https://owencalvin.github.io/discord.ts/)**

# 📟 @Slash - Discord commands
Discord has it's own command system now, you can simply declare commands and use Slash commands this way

```ts
import { Discord, Slash } from "@typeit/discord";
import { CommandInteraction } from "discord.js";

@Discord()
abstract class AppDiscord {
  @Slash("hello")
  private hello(
    @Option("text")
    text: string,
    interaction: CommandInteraction
  ) {
    // ...
  }
}
```

## Decorators related to Slash commands
There is a whole system that allows you to implement complex Slash commands
- `@Choice`
- `@Choices`
- `@Option`
- `@Permission`
- `@Guild`
- `@Group`
- `@Description`
- `@Guard`

# 💡@On / @Once - Discord events
We can declare methods that will be executed whenever a Discord event is triggered.  

Our methods must be decorated with the `@On(event: string)` or `@Once(event: string)` decorator.  

That's simple, when the event is triggered, the method is called:

```typescript
import { Discord, On, Once } from "@typeit/discord";

@Discord()
abstract class AppDiscord {
  @On("message")
  private onMessage() {
    // ...
  }

  @Once("messageDelete")
  private onMessageDelete() {
    // ...
  }
}
```

# ⚔️ Guards
We implemented a guard system thats work pretty like the [Koa](https://koajs.com/) middleware system

You can use functions that are executed before your event to determine if it's executed. For example, if you want to apply a prefix to the messages, you can simply use the `@Guard` decorator.

The order of execution of the guards is done according to their position in the list, so they will be executed in order (from top to bottom).

Guards can be set for `@Slash`, `@On`, `@Once`, `@Discord` and globaly.

```typescript
import { Discord, On, Client, Guard } from "@typeit/discord";
import { NotBot } from "./NotBot";
import { Prefix } from "./Prefix";

@Discord()
abstract class AppDiscord {
  @On("message")
  @Guard(
    NotBot, // You can use multiple guard functions, they are excuted in the same order!
    Prefix("!")
  )
  async onMessage([message]: ArgsOf<"message">) {
    switch (message.content.toLowerCase()) {
      case "hello":
        message.reply("Hello!");
        break;
      default:
        message.reply("Command not found");
        break;
    }
  }
}
```

# 📡 Installation
Use [npm](https://www.npmjs.com/package/@typeit/discord) or yarn to install **@typeit/discord@slash** with **discord.js**

**[Please refer to the documentation](https://owencalvin.github.io/discord.ts/installation/#installation)**


# ☎️ Need help?

**[Simply join the Discord server](https://discord.gg/VDjwu8E)**  

You can also find help with the [different projects that use discord.ts](https://github.com/OwenCalvin/discord.ts/network/dependents?package_id=UGFja2FnZS00Njc1MzYwNzU%3D) and in the [examples folder](https://github.com/OwenCalvin/discord.ts/tree/master/examples)

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