0.3.0 • Published 9 months ago

@peridotjs/framework v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

@peridot/framework

GitHub npm

The core framework package for PeridotJS, providing a functional and type-safe approach to building Discord bots.

InstallationQuick StartHandlersContainerExamples

Installation

# npm
npm install @peridot/framework discord.js

# yarn
yarn add @peridot/framework discord.js

# pnpm
pnpm add @peridot/framework discord.js

Quick Start

import { PeridotClient, PermissionLevel } from '@peridot/framework';
import { GatewayIntentBits } from 'discord.js';
import pino from 'pino';

// Create a new client instance
const client = new PeridotClient({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
    ],
    logger: pino(),
    permissionConfig: {
        global: {
            'YOUR_USER_ID': PermissionLevel.OWNER,
        },
    },
});

// Load handlers from the handlers directory
await container.handlers.loadHandlerExports(
    new URL('handlers/', import.meta.url).pathname
);

// Login to Discord
client.login('YOUR_BOT_TOKEN');

Container

The container is a central registry that provides access to core framework components. It's inspired by SapphireJS's container system but implemented with a more functional approach.

import { container } from '@peridot/framework';

// Access the client instance
const client = container.client;

// Access the handler registry manager
const handlers = container.handlers;

// Access the logger
const logger = container.logger;

Handlers

Handlers are the core building blocks of your bot's functionality. They can be commands, events, or components.

Creating a Handler

Create a new file in your handlers directory (e.g., src/handlers/ping.ts):

import { createHandlerExport, type SlashCommand } from '@peridot/framework';

const pingCommand = {
    data: {
        name: 'ping',
        description: 'Replies with pong!',
    },
    guilds: ["MY_GUILD_ID"],
    async run(interaction) {
        await interaction.reply('Pong!');
    },
} satisfies SlashCommand;

export default createHandlerExport({
    slashCommands: [pingCommand],
});

Loading Handlers

Handlers are loaded using the loadHandlerExports method from the container:

// Load all handlers from the handlers directory
await container.handlers.loadHandlerExports(
    new URL('handlers/', import.meta.url).pathname
);

Handler Types

  • Commands
    • Text Commands
    • Slash Commands
    • Context Menu Commands
  • Components
    • Button Components
    • Modal Components
    • Select Menu Components
  • Events
    • Client Events

Features

  • 🎯 Type-Safe: Built with TypeScript for excellent type safety
  • 🔌 Plugin System: Extensible plugin architecture
  • 🛡️ Permission System: Built-in hierarchical permission system
  • 🌍 i18n Support: Internationalization support using i18next
  • 🎮 Full Discord.js Support: Complete support for all Discord.js features
  • 🔍 Argument Parsing: Advanced argument parsing with flags
  • 📝 Logger Integration: Built-in logging support using Pino

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Related Packages

0.3.0

9 months ago

0.2.7

9 months ago

0.2.6

10 months ago

0.1.0

1 year ago

0.2.1

1 year ago

0.1.2

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.2.3

1 year ago

0.1.4

1 year ago

0.2.2

1 year ago

0.1.3

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago