0.0.1 • Published 3 years ago

open-discord.ts v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

About

DiscordTS was forked from the original discord.ts. It is built on discord.js, so the internals are the same.

Table of Contents

Setup

💾 Installation

Use npm or yarn to install open-discord.ts with discord.js:

npm i open-discord.ts discord.js

Setup and start your application

Your tsconfig.json should look like this:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2017",
    "noImplicitAny": false,
    "sourceMap": true,
    "outDir": "build",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "forceConsistentCasingInFileNames": true,
    "lib": [
      "es2017",
      "esnext.asynciterable"
    ],
    "moduleResolution": "node"
  },
  "exclude": [
    "node_modules"
  ]
}

In order to start your application, you must use the discord.ts's Client (not the client that is provided by discord.js!).
It works the same as the discord.js's Client (same methods, properties, ...).

You have different parameters in addition to discord.js when you initialize your Client:

  • classes (required):
    Indicate the class jacket of your classes containing the @Discord decorator. It accepts a list of classes or of (glob) paths.

  • silent (false by default):
    Allows you to disable your event information at startup.

  • variablesChar (":" by default):
    Allows you to change the prefix character of a variable.

You must specify the glob path(s) where your decorated classes are

// Use the Client that are provided by @typeit/discord NOT discord.js
import { Client } from "@typeit/discord";

async function start() {
  const client = new Client({
    classes: [
      `${__dirname}/*Discord.ts`, // glob string to load the classes
      `${__dirname}/*Discord.js` // If you compile using "tsc" the file extension change to .js
    ],
    silent: false,
    variablesChar: ":"
  });

  await client.login("YOUR_TOKEN");
}

start();

☎️ Help

Join the Discord Server You can also find help in the examples folder

💬 Feedback

Join the Discord Server

Migration v1 to v2

You should just add parenthesis after the @Discord decorator, everywhere in your app.
@Discord class X should now be @Discord() class X.

Migration v2 to v3

Now the payloadInjection policy is by default "first", convert each events of your app or change your payloadInjection policy to "spread" inside the Client constructor:

const client = new Client({
  payloadInjection: "spread"
})

Migration v3 to v4

payloadInjection policy doesn't exists anymore, moreover the parameters inside the decorators has changed, please refer to the documentation or ask help using the discord server.

See also