Coder Social home page Coder Social logo

owengombas / discord.ts Goto Github PK

View Code? Open in Web Editor NEW
322.0 7.0 41.0 1.03 MB

๐Ÿค– Create your discord bot by using TypeScript and decorators!

Home Page: https://owencalvin.github.io/discord.ts/

TypeScript 99.62% JavaScript 0.18% Shell 0.20%
discord discord-bot typescript decorators bot type command slash slash-commands

discord.ts's Introduction




discord.ts (@typeit/discord)

Create your discord bot by using TypeScript and decorators!


โš ๏ธ DEPRECATION & Maintained project

This repo is no longer maintained due to my studies, but a fork of the project is active and maintained by @oceanroleplay and the community. Please use their version of the project available here: github.com/oceanroleplay/discord.ts.

Known as discordx on NPM

๐ŸŽป 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 !

๐Ÿ“œ Documentation

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

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:

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

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 or yarn to install @typeit/discord@slash with discord.js

Please refer to the documentation

โ˜Ž๏ธ Need help?

Simply join the Discord server

You can also find help with the different projects that use discord.ts and in the examples folder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.