Sapphire Framework Documentation
website·Indexed 33 days ago
https://www.sapphirejs.dev/API documentation for the Sapphire framework, including core pieces, framework resolvers, and various plugins such as @sapphire/plugin-scheduled-tasks, @sapphire/plugin-pattern-commands, @sapphire/plugin-api, and @sapphire/plugin-subcommands.
What's inside Sapphire
- The Sapphire Community provides a suite of specialized utility libraries for JavaScript and TypeScript developers, ranging from Discord-specific helpers to general-purpose data structures and time management tools.
Overview of the Option class in @sapphire/result
TheOption<T, Exists>class represents an optional value: it either contains a value of typeT(Some) or contains no value (None). It uses a type parameterExists(boolean) to track whether a value is present at the type level.Overview of @sapphire/lexure
@sapphire/lexure is a fast parser and utility set for non-technical user input. It is written in TypeScript and supports NodeJS and browsers (CommonJS, ESM, and UMD). Key features include parsing quoted input with multiple quote styles, a customizable strategy system for flags and options, preservation of leading whitespace, and custom argument delimiters.Overview of the Sapphire Discord Bot Framework
Sapphire is a modular and extendable Discord bot framework built on top of discord.js. It is written in TypeScript and provides full support for both TypeScript and JavaScript. Key features include a Command Handler, Arguments, Pre-conditions, a Listeners Store, and advanced plugin support.Overview of Result and Option types
The
@sapphire/resultlibrary provides a TypeScript port of Nightly Rust'sResult<T, E>andOption<T>structs.Result: A type union used to express computations that can fail. It consists of two variants:Ok(T)(representing success and containing a value) andErr(E)(representing error and containing an error value).Option: A type used to represent a value that may or may not be present.
Overview of @sapphire/async-queue features
@sapphire/async-queueis a sequential asynchronous lock-based queue for promises. It is written in TypeScript, bundled with esbuild for compatibility with both Node.js and browsers, and provides CommonJS, ESM, and UMD bundles.Overview of @sapphire/lexure
@sapphire/lexure is a fast parser and utility library designed for non-technical user input. It is written in TypeScript and supports NodeJS and browsers (via CommonJS, ESM, and UMD bundles). Key features include support for multiple quote styles, customizable flag/option parsing strategies, preservation of leading whitespace, and custom argument delimiters.Overview of the Sapphire API plugin
The@sapphire/plugin-apiprovides an API endpoint for a bot that can be called from external services. This is particularly useful for creating a web dashboard where end-users can modify bot configuration settings via a website that interfaces with the bot.Overview of @sapphire/result
The@sapphire/resultpackage is a TypeScript port of Nightly Rust'sResult<T, E>andOption<T>structs. It is designed to alleviate the chaos of nested or sequentialtry-catchblocks by providing a functional way to express computations that can fail, propagate errors, and handle optional values.Overview of TimerManager
TheTimerManagerclass manages timers (timeouts and intervals) so that an application can be cleanly exited. It tracks all timers created through its static methods and provides a mechanism to clear them all at once.Overview of the CommandStore class
TheCommandStoreclass is used to store and manage allCommandpieces within the Sapphire framework. It extendsAliasStore<Command, "commands">and has been available since version 1.0.0.Overview of @sapphire/plugin-utilities-store
The
@sapphire/plugin-utilities-storeplugin for the Sapphire framework provides an automatically imported utilities store. This allows developers to centralize external utility functions and access them through the Sapphirecontainer.Important Constraint: Utility functions are only available on the
containerafter the bot has logged in. Any functions required during the pre-login phase must be exported using standard module loading (e.g.,export/require).