Skip to content

DiscordPlugin

This file defines the DiscordPlugin class, which implements the Discord integration plugin for the @sodacore/core framework. The plugin registers all necessary Discord services, providers, and scripts, and loads metadata from the package's package.json.


Features

  • Automatic Metadata Loading: Reads plugin metadata (name, version, description, author) from package.json at runtime.
  • Service Registration: Registers Discord-related services, providers, and scripts with the application during installation.
  • Extends BasePlugin: Inherits from BasePlugin for consistent plugin lifecycle and configuration handling.

Usage

typescript
import DiscordPlugin from './module/plugin';
import Application from '@sodacore/core';

const app = new Application();
const discordPlugin = new DiscordPlugin();
await discordPlugin.install(app);

API

Properties

  • name: The plugin name, loaded from package.json.
  • version: The plugin version, loaded from package.json.
  • description: The plugin description, loaded from package.json.
  • author: The plugin author, loaded from package.json.

Constructor

typescript
constructor(protected config: IConfig = {})
  • config: Optional configuration object for the plugin.

Methods

async install(app: Application): Promise<void>

Registers all Discord-related modules and providers with the application:

  • DiscordScripts
  • PromptsHelper
  • DiscordService
  • OAuthProvider
  • SlashCommandsProvider

How It Works

  1. Loads plugin metadata from package.json using Bun's file API.
  2. Sets the plugin's metadata properties.
  3. On installation, registers all required Discord modules and providers with the Sodacore application instance.

Notes

  • This plugin is designed to be used with the Sodacore framework and expects Bun as the runtime.
  • Throws an error if package.json is not found.
  • All Discord-related functionality is encapsulated and registered via the install method.

Released under the Apache-2.0 License.