discordx-ts / discordx

🤖 Create a discord bot with TypeScript and Decorators!
https://discordx.js.org
Apache License 2.0
588 stars 50 forks source link

feat(discordx): plugins support #920

Closed samarmeena closed 1 year ago

samarmeena commented 1 year ago

Plugin

Develop plugins for discordx. You can publish your plugin on NPM. Maintain a single codebase while using them on different bots.

Create a Plugin

import { dirname, importx } from "@discordx/importer";
import { Plugin } from "discordx";

export class HelperPlugin extends Plugin {
  async init(): Promise<void> {
    // This section is similar to the bot login section. However, here we are doing this for a plugin.
    await importx(`${dirname(import.meta.url)}/commands/**/*.{js,ts}`);
  }
}

Use a plugin with discordx client

import { Client, MetadataStorage } from "discordx";

// Initialize the plugin
const helperPlugin = new HelperPlugin({ metadata: MetadataStorage.instance });

// Provide plugins to client
new Client({ plugins: [helperPlugin] });

To-Do