Skip to main content

Sapphire Logo

@sapphire/discord-utilities

Discord specific utilities for your JavaScript/TypeScript bots.

GitHub npm bundle size npm

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 WithAddress
Open CollectiveClick Here
Ko-fiClick Here
PatreonClick Here
PayPalClick 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

ClassDescription
InteractionOptionResolverUtility 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

VariableDescription
ActionMetadataLimitsNamespace containing limits related to Discord Auto Moderation Action Metadata.
AllowedMentionsLimitsNamespace containing limits related to Discord Message Allowed Mentions.
ApplicationCommandLimitsNamespace containing limits related to Discord application commands (slash commands).
ApplicationCommandOptionLimitsNamespace containing limits related to Choices of Discord Application Commands.
ApplicationCommandPermissionLimitsNamespace containing limits related to Permissions of Discord Application Commands.
ApplicationRoleConnectionLimitsNamespace containing limits related to Discord Application Role Connections.
AutoCompleteLimitsNamespace container limits related to Discord autocomplete interactions.
AutoModerationRuleLimitsNamespace containing limits related to Discord Auto Moderation Rules.
ButtonLimitsNamespace containing limits related to Message Buttons.
ChannelInviteLimitsNamespace containing limits related to Discord Channel Invites.
ChannelLimitsNamespace containing limits related to Discord channels.
ChannelMentionRegexRegex that can capture the ID in Discord Channel mentions
ChannelMessageRegexRegex 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
DiscordHostnameRegexRegex that matches links on the known Discord host names
DiscordInviteLinkRegexRegex that can can capture the code of Discord invite links
EmbedLimitsNamespace containing limits related to Discord embeds.
EmojiLimitsNamespace containing limits related to Discord emojis.
EmojiRegexRegex that can capture the ID of any animated or non-animated custom Discord emoji
FormattedCustomEmojiRegex that matches any animated or non-animated custom Discord emoji. Unlike EmojiRegex It can be a substring of a larger string.
FormattedCustomEmojiWithGroupsRegex 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.
GuildAuditLogsLimitsNamespace containing limits related to Discord Guild Audit Logs.
GuildBansLimitsNamespace containing limits related to Discord guild bans.
GuildIntegrationLimitsNamespace containing limits related to Discord Guild Integrations.
GuildLimitsNamespace containing limits related to Discord guilds.
GuildMemberLimitsNamespace containing limits related to Discord guild members.
GuildScheduledEventLimitsNamespace containing limits related to Discord guild scheduled events.
HttpUrlRegexRegex that matches any URL starting with http or https
InteractionLimitsNamespace containing limits related to Discord interactions.
MessageLimitsNamespace containing limits related to Discord messages.
MessageLinkRegexRegex that can capture the Guild, Channel, and Message ID based on a shareable Discord message link.
ModalLimitsNamespace containing limits related to Discord Modals.
ModerationLimitsNamespace containing limits related to built-in moderation features.
ParsedCustomEmojiRegex 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.
ParsedCustomEmojiWithGroupsRegex 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.
PremiumGuildLimitsNamespace containing limits related to premium Discord guilds.
ReactionLimitsNamespace containing limits related to Discord message reactions.
RoleLimitsNamespace containing limits related to Discord roles.
RoleMentionRegexRegex that can capture the ID in Discord Role mentions
SelectMenuLimitsNamespace containing limits related to Select Menus.
SnowflakeRegexRegex that can capture any Discord Snowflake ID
StageChannelLimitsNamespace containing limits related to Discord stage channels.
StickerLimitsNamespace containing limits related to Discord Stickers.
TextChannelLimitsNamespace containing limits related to Discord text channels.
TextInputLimitsNamespace containing limits related to Discord Modal Text Input component.
ThreadLimitsNamespace containing limits related to Discord threads.
TokenRegexRegex that can capture a Discord Token
TriggerMetadataLimitsNamespace containing limits related to Discord Auto Moderation Trigger Metadata.
TriggerTypeLimitsNamespace containing limits related to Discord Auto Moderation Triggers.
TwemojiRegexRegex that can capture a Twemoji (Twitter Emoji)
UserLimitsNamespace containing limits related to Discord users and Direct Messages.
UserOrMemberMentionRegexRegex that can capture the ID of a user in Discord user mentions
VoiceChannelLimitsNamespace containing limits related to Discord voice channels.
WebhookRegexRegex that captures the Webhook ID and token from a Discord Webhook URL.
WebSocketUrlRegexRegex that matches any WebSocket URL starting with ws or wss

Functions

FunctionDescription
createTwemojiRegexCreates 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