Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
10BC0 GitHub - purinton/discord: A modular, extensible Discord app framework for Node.js with slash command, localization, and event-driven support.
Nothing Special   »   [go: up one dir, main page]

Skip to content

A modular, extensible Discord app framework for Node.js with slash command, localization, and event-driven support.

License

Notifications You must be signed in to change notification settings

purinton/discord

Repository files navigation

Purinton Dev

@purinton/discord npm versionlicensebuild status

A modular, extensible Discord app framework for Node.js, with built-in support for slash commands, localization, and event-driven architecture.


Table of Contents

Features

  • Simple, opinionated Discord app setup for Node.js
  • Slash command registration and handler auto-loading
  • Event handler auto-loading for all Discord Gateway events
  • Built-in localization system with easy locale file management
  • TypeScript type definitions included
  • Dependency injection and testability for all major components
  • Logging and error handling hooks
  • Extensible and modular directory structure

Installation

npm install @purinton/discord

Usage

ESM Example

import 'dotenv/config';
import log from '@purinton/log';
import path from '@purinton/path';
import { createDiscord } from '@purinton/discord';

try {
  await createDiscord({
    log,
    rootDir: path(import.meta),
    intents: { MessageContent: true }
  });
} catch (err) {
    log.error('Failed to start app:', err);
}

CommonJS Example

require('dotenv/config');
const log = require('@purinton/log').default;
const path = require('@purinton/path').default;
const { createDiscord } = require('@purinton/discord');

(async () => {
  try {
    await createDiscord({
      log,
      rootDir: path(__filename),
      intents: { MessageContent: true }
    });
  } catch (err) {
    log.error('Failed to start app:', err);
  }
})();

API

createDiscord(options): Promise<Client>

Creates and logs in a Discord client, auto-registers commands, loads event handlers, and sets up localization.

Options:

  • client_id (string): Discord application client ID (required)
  • token (string): Discord bot token (required)
  • log (Logger): Logger instance (optional)
  • rootDir (string): Root directory for events, commands, and locales (default: autodetect)
  • localesDir (string): Directory for locale files (default: <rootDir>/locales)
  • commandsDir (string): Directory for command definitions and handlers (default: <rootDir>/commands)
  • eventsDir (string): Directory for event handlers (default: <rootDir>/events)
  • intents (object): Discord Gateway Intents (default: Guilds and GuildMessages enabled)
  • partials (array): Discord.js partials (default: ['MESSAGE', 'CHANNEL', 'REACTION'])
  • clientOptions (object): Additional Discord.js client options
  • ClientClass (constructor): Custom Discord.js Client class (for testing)
  • setupEventsFn, setupCommandsFn, registerCommandsFn, setupLocalesFn: Dependency injection for advanced use/testing
  • context (object): Additional arbitrary data to be injected into all event and command handlers

Returns: A logged-in Discord.js Client instance.

splitMsg(msg, maxLength = 2000): string[]

Splits a message into chunks of up to maxLength characters, attempting to split at newlines or periods for readability.

  • msg (string): The message to split
  • maxLength (number, optional): The maximum length of each chunk (default: 2000)
  • Returns: An array of message chunks, each no longer than maxLength.

Command and Event Structure

  • Commands:
    • Place .json files in the commands/ directory for each command definition (see commands/help.json for structure).
    • Place a .mjs file with the same name for the command handler (see commands/help.mjs).
  • Events:
    • Place .mjs files in the events/ directory, named after Discord Gateway events (e.g., ready.mjs, messageCreate.mjs).

Localization

  • Place locale files in the locales/ directory (e.g., en-US.json, es-ES.json).
  • Each file should be a flat key-value JSON object for that locale.

TypeScript

Type definitions are included and cover all public APIs and options:

import type { CreateDiscordOptions } from '@purinton/discord';

declare function createDiscord(options?: CreateDiscordOptions): Promise<Client>;

Support

For help, questions, or to chat with the author and community, visit:

DiscordPurinton Dev

Purinton Dev on Discord

License

MIT © 2025 Russell Purinton

Links


0