Seyfert Discord Framework
repository·main·Indexed 43 days ago
https://github.com/tiramisulabs/seyfertA 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.
What's inside Seyfert
- Seyfert is a bleeding-edge, non-bloated Discord framework designed for high performance and minimal overhead. It provides a streamlined way to interact with the Discord API.
Understand the Discord API type naming conventions
mainThe 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
APIprefix: Represents a payload that may come from either the REST API or the Gateway.Gatewayprefix: Represents data that only comes from or is directly related to the Gateway.RESTprefix: 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
RESTOAuth2orREST<HTTP Method>OAuth2.
The
ResultSuffixIf a type ends with
Result, it represents the expected return value of its corresponding route. If a type is exported asnever, it typically indicates a204 No Contentresponse (ignoring errors).Install Seyfert via Deno
mainIf you are using Deno, you can add
seyfertusing the following command:deno add npm:seyfertInstall Seyfert
mainInstall the
seyfertpackage using your preferred package manager.Runtime Requirements:
- Node.js v18 or higher (or v16 with the
--experimental-fetchflag) - Deno v2.6.9 or higher
- Bun/Node/Deno LTS versions are recommended.
pnpm add seyfert- Node.js v18 or higher (or v16 with the
Install Seyfert via npm
mainIf you are using npm, you can add
seyfertusing the following command:npm i seyfertInstall Seyfert via Bun
mainIf you are using Bun, you can add
seyfertusing the following command:bun add seyfertInstall discord-api-types
mainYou can install the
discord-api-typespackage using npm, yarn, or pnpm.npm install discord-api-types yarn add discord-api-types pnpm add discord-api-typesImport discord-api-types in Deno
mainFor the Deno runtime, you can import types using one of the following three methods. Always specify the version (e.g.,
v10) in the URL.- Directly from GitHub
- From deno.land/x
- 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';Import discord-api-types in Node.js or TypeScript
mainWhen 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*(Includesgateway,payloads,rest,rpc,utils, andglobalsfor 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';Implement a custom cache adapter in Seyfert
mainSeyfert 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 adefaultimplementation, alimitedimplementation, and aworkeradapterfor specific environments. Developers can extend these interfaces to integrate external caching solutions like Redis or Memcached into the Seyfert ecosystem.Customize command error handling
mainSeyfert provides several lifecycle hooks to handle errors gracefully during command execution. You can override these in your command definitions:
onAutocompleteError(interaction, error): Called when theautocompletecallback throws an error.onPermissionsFail(context, permissions): Called when a member lacks thedefaultMemberPermissionsrequired by the command.onBotPermissionsFail(context, permissions): Called when the bot lacks thebotPermissionsrequired by the command.onOptionsError(context, errors): Called when option parsing or validation fails. Theerrorsobject contains details about which options failed and why.onMiddlewaresError(context, error, metadata): Called when a middleware fails.metadataincludes the middleware name and its scope (globalorcommand).onRunError(context, error): Called when the mainrunmethod throws an error.onInternalError(client, command, error): A catch-all for unexpected errors during the command lifecycle.
Extend the cache with custom plugin resources
mainYou can extend the
Cacheclass by contributing custom resources via thepluginRegistry. This allows plugins to add their own managed data structures and handle gateway packets.A contribution object should follow the
PluginCacheResourceContributionLikeinterface:name: Unique name for the resource.resource: A class that takes(cache: Cache, client: UsingClient)in its constructor.onPacket(optional): A function to handle specificGatewayDispatchPayloadevents.sequence: Number used to sort the execution order of plugin resources.