Description
When developing Discord bots or frameworks for Discord bots we often run into certain constants such as regex's, channel type resolutions and other common functions that would be really nice to get from 1 centralized place. That's where @sapphire/discord-utilities come in. This package provides common Discord specific utilities for your Discord bots.
Important: If you're looking for Discord.js specific utilities then install @sapphire/discord.js-utilities instead. @sapphire/discord.js-utilities re-exports this package at the root level and peer-depends on this package.
Features
- Written in TypeScript
- Bundled with esbuild so it can be used in NodeJS and browsers
- Offers CommonJS, ESM and UMD bundles
- Fully tested
- Discord library agnostic
Installation
You can use the following command to install this package, or replace npm install
with your package manager of choice.
npm install @sapphire/discord-utilities
Buy us some doughnuts
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
Donate With | Address |
---|---|
Open Collective | Click Here |
Ko-fi | Click Here |
Patreon | Click Here |
PayPal | Click Here |
Contributors
Please make sure to read the Contributing Guide before making a pull request.
Thank you to all the people who already contributed to Sapphire!
Classes
Class | Description |
---|---|
InteractionOptionResolver | Utility class for resolving command interaction options while working with the raw API. Based on https://github.com/discordjs/discord.js/blob/main/packages/discord.js/src/structures/CommandInteractionOptionResolver.js |
Variables
Variable | Description |
---|---|
ActionMetadataLimits | Namespace containing limits related to Discord Auto Moderation Action Metadata. |
AllowedMentionsLimits | Namespace containing limits related to Discord Message Allowed Mentions. |
ApplicationCommandLimits | Namespace containing limits related to Discord application commands (slash commands). |
ApplicationCommandOptionLimits | Namespace containing limits related to Choices of Discord Application Commands. |
ApplicationCommandPermissionLimits | Namespace containing limits related to Permissions of Discord Application Commands. |
ApplicationRoleConnectionLimits | Namespace containing limits related to Discord Application Role Connections. |
AutoCompleteLimits | Namespace container limits related to Discord autocomplete interactions. |
AutoModerationRuleLimits | Namespace containing limits related to Discord Auto Moderation Rules. |
ButtonLimits | Namespace containing limits related to Message Buttons. |
ChannelInviteLimits | Namespace containing limits related to Discord Channel Invites. |
ChannelLimits | Namespace containing limits related to Discord channels. |
ChannelMentionRegex | Regex that can capture the ID in Discord Channel mentions |
ChannelMessageRegex | Regex that can capture the channel and message IDs in a channelId-messageId pattern This pattern can be found when you hold Shift and hover over a message, and click the "ID" button |
DiscordHostnameRegex | Regex that matches links on the known Discord host names |
DiscordInviteLinkRegex | Regex that can can capture the code of Discord invite links |
EmbedLimits | Namespace containing limits related to Discord embeds. |
EmojiLimits | Namespace containing limits related to Discord emojis. |
EmojiRegex | Regex that can capture the ID of any animated or non-animated custom Discord emoji |
FormattedCustomEmoji | Regex that matches any animated or non-animated custom Discord emoji. Unlike EmojiRegex It can be a substring of a larger string. |
FormattedCustomEmojiWithGroups | Regex that can capture any animated or non-animated custom Discord emoji. Similar to FormattedCustomEmoji and unlike EmojiRegex can also be a substring of a larger string. |
GuildAuditLogsLimits | Namespace containing limits related to Discord Guild Audit Logs. |
GuildBansLimits | Namespace containing limits related to Discord guild bans. |
GuildIntegrationLimits | Namespace containing limits related to Discord Guild Integrations. |
GuildLimits | Namespace containing limits related to Discord guilds. |
GuildMemberLimits | Namespace containing limits related to Discord guild members. |
GuildScheduledEventLimits | Namespace containing limits related to Discord guild scheduled events. |
HttpUrlRegex | Regex that matches any URL starting with http or https |
InteractionLimits | Namespace containing limits related to Discord interactions. |
MessageLimits | Namespace containing limits related to Discord messages. |
MessageLinkRegex | Regex that can capture the Guild, Channel, and Message ID based on a shareable Discord message link. |
ModalLimits | Namespace containing limits related to Discord Modals. |
ModerationLimits | Namespace containing limits related to built-in moderation features. |
ParsedCustomEmoji | Regex that matches any animated or non-animated custom Discord emoji *without the wrapping <...> symbols. This means that a string that matches this regex can directly be send inside a Discord message. Other than this difference it is similar to FormattedCustomEmoji. |
ParsedCustomEmojiWithGroups | Regex that matches any animated or non-animated custom Discord emoji *without the wrapping <...> symbols. This means that a string that matches this regex can directly be send inside a Discord message. Other than this difference it is similar to FormattedCustomEmojiWithGroups. |
PremiumGuildLimits | Namespace containing limits related to premium Discord guilds. |
ReactionLimits | Namespace containing limits related to Discord message reactions. |
RoleLimits | Namespace containing limits related to Discord roles. |
RoleMentionRegex | Regex that can capture the ID in Discord Role mentions |
SelectMenuLimits | Namespace containing limits related to Select Menus. |
SnowflakeRegex | Regex that can capture any Discord Snowflake ID |
StageChannelLimits | Namespace containing limits related to Discord stage channels. |
StickerLimits | Namespace containing limits related to Discord Stickers. |
TextChannelLimits | Namespace containing limits related to Discord text channels. |
TextInputLimits | Namespace containing limits related to Discord Modal Text Input component. |
ThreadLimits | Namespace containing limits related to Discord threads. |
TokenRegex | Regex that can capture a Discord Token |
TriggerMetadataLimits | Namespace containing limits related to Discord Auto Moderation Trigger Metadata. |
TriggerTypeLimits | Namespace containing limits related to Discord Auto Moderation Triggers. |
TwemojiRegex | Regex that can capture a Twemoji (Twitter Emoji) |
UserLimits | Namespace containing limits related to Discord users and Direct Messages. |
UserOrMemberMentionRegex | Regex that can capture the ID of a user in Discord user mentions |
VoiceChannelLimits | Namespace containing limits related to Discord voice channels. |
WebhookRegex | Regex that captures the Webhook ID and token from a Discord Webhook URL. |
WebSocketUrlRegex | Regex that matches any WebSocket URL starting with ws or wss |
Functions
Function | Description |
---|---|
createTwemojiRegex | Creates a fresh instance of the Twemoji regex, which is useful if you don't want to worry about the effects of a global regex and the lastIndex |