Seyfert Discord Framework

repository·main·Indexed 43 days ago

https://github.com/tiramisulabs/seyfert

A high-performance, type-safe Discord framework for scalable bot development. Seyfert version 5.1.0 focuses on low RAM usage and advanced cache control, supporting Node.js v18+, Deno v2.6.9+, and Bun. It features a comprehensive builder system for UI components, a flexible caching layer with custom adapter support, and a plugin-extensible Client for managing shards and gateway connections.

Tokens
34.9K
Snippets
115
Records
167
Agent score
56%

What's inside Seyfert

  1. Understand the Discord API type naming conventions

    main

    The package organizes types based on their source and purpose. Understanding these prefixes helps you identify where data originates and how to use it.

    Type Prefixes

    • API prefix: Represents a payload that may come from either the REST API or the Gateway.
    • Gateway prefix: Represents data that only comes from or is directly related to the Gateway.
    • REST prefix: Represents data that only comes from or is directly related to the REST API.

    REST Endpoint Type Structure

    Endpoint options follow a specific naming pattern: REST<HTTP Method><Type><Query|(JSON|FormData)Body|Result>

    • Example (Body): RESTPostAPIChannelMessageJSONBody
    • Example (Result): RESTGetAPIGatewayBotInfoResult
    • Note on OAuth2: Some OAuth2 types may deviate slightly, starting with RESTOAuth2 or REST<HTTP Method>OAuth2.

    The Result Suffix

    If a type ends with Result, it represents the expected return value of its corresponding route. If a type is exported as never, it typically indicates a 204 No Content response (ignoring errors).

  2. Install Seyfert

    main

    Install the seyfert package using your preferred package manager.

    Runtime Requirements:

    • Node.js v18 or higher (or v16 with the --experimental-fetch flag)
    • Deno v2.6.9 or higher
    • Bun/Node/Deno LTS versions are recommended.
    pnpm add seyfert
  3. Import discord-api-types in Deno

    main

    For the Deno runtime, you can import types using one of the following three methods. Always specify the version (e.g., v10) in the URL.

    1. Directly from GitHub
    2. From deno.land/x
    3. From skypack.dev
    // 1. Directly from GitHub
    import { APIUser } from 'https://raw.githubusercontent.com/discordjs/discord-api-types/main/deno/v10.ts';
    
    // 2. From deno.land/x
    import { APIUser } from 'https://deno.land/x/discord_api_types/v10.ts';
    
    // 3. From skypack.dev
    import { APIUser } from 'https://cdn.skypack.dev/discord-api-types/v10?dts';
  4. Import discord-api-types in Node.js or TypeScript

    main

    When importing from discord-api-types, you must specify the API version you want to target by appending /v* to the import path (e.g., /v10).

    Common Import Paths

    You can import from the root versioned path or specific sub-modules:

    • discord-api-types/v* (Includes gateway, payloads, rest, rpc, utils, and globals for that version)
    • discord-api-types/gateway/v*
    • discord-api-types/payloads/v*
    • discord-api-types/rest/v*
    • discord-api-types/rpc/v*
    • discord-api-types/utils/v*
    • discord-api-types/voice/v*
    // TypeScript/ES Module support
    import { APIUser } from 'discord-api-types/v10';
    
    // Importing specific sub-modules
    import { GatewayVersion } from 'discord-api-types/gateway/v10';
  5. Implement a custom cache adapter in Seyfert

    main
    Seyfert provides a set of interfaces for implementing custom caching layers. To create a custom adapter, you must implement the core types defined in the cache system. The available adapter types include a default implementation, a limited implementation, and a workeradapter for specific environments. Developers can extend these interfaces to integrate external caching solutions like Redis or Memcached into the Seyfert ecosystem.
  6. Customize command error handling

    main

    Seyfert provides several lifecycle hooks to handle errors gracefully during command execution. You can override these in your command definitions:

    • onAutocompleteError(interaction, error): Called when the autocomplete callback throws an error.
    • onPermissionsFail(context, permissions): Called when a member lacks the defaultMemberPermissions required by the command.
    • onBotPermissionsFail(context, permissions): Called when the bot lacks the botPermissions required by the command.
    • onOptionsError(context, errors): Called when option parsing or validation fails. The errors object contains details about which options failed and why.
    • onMiddlewaresError(context, error, metadata): Called when a middleware fails. metadata includes the middleware name and its scope (global or command).
    • onRunError(context, error): Called when the main run method throws an error.
    • onInternalError(client, command, error): A catch-all for unexpected errors during the command lifecycle.
  7. Extend the cache with custom plugin resources

    main

    You can extend the Cache class by contributing custom resources via the pluginRegistry. This allows plugins to add their own managed data structures and handle gateway packets.

    A contribution object should follow the PluginCacheResourceContributionLike interface:

    • name: Unique name for the resource.
    • resource: A class that takes (cache: Cache, client: UsingClient) in its constructor.
    • onPacket (optional): A function to handle specific GatewayDispatchPayload events.
    • sequence: Number used to sort the execution order of plugin resources.