detritus

Utilsnamespace

Builders for embeds, components and modals, plus markup, permission and regex helpers.

On this page
import { Utils } from 'detritus-client';
2 namespaces · 32 classes · 25 interfaces · 16 type aliases · 1 variables · 25 functions

Namespaces

Grouped exports, reached as properties of the package.

Classes

Classes you create or receive from the library.

classComponentActionBase The most basic Structure class, every structure extends this 4 properties · 3 methods classComponentActionRow Utils Component Action Row Structure 8 properties · 9 methods classComponentButton Utils Component Button Structure 8 properties · 8 methods classComponentCheckbox Utils Component Checkbox Structure, only usable in modals inside of a label 3 properties · 3 methods classComponentCheckboxGroup Utils Component Checkbox Group Structure, only usable in modals inside of a label 6 properties · 7 methods classComponentContainer Utils Component Container Structure 7 properties · 17 methods classComponentContext 68 properties · 12 methods classComponentFile Utils Component File Structure 4 properties · 5 methods classComponentFileUpload Utils Component File Upload Structure, only usable in modals inside of a label 6 properties · 7 methods classComponentInputText Utils Component Input Text Structure 9 properties classComponentLabel Utils Component Label Structure, used to wrap a single component inside of a modal 5 properties · 12 methods classComponentMediaGallery Utils Component Media Gallery Structure 3 properties · 5 methods classComponentMediaGalleryItem Utils Component Media Gallery Item Structure 3 properties · 4 methods classComponentRadioGroup Utils Component Radio Group Structure, only usable in modals inside of a label 4 properties · 5 methods classComponents Utils Components Structure 6 properties · 28 methods classComponentSection Utils Component Section Structure 8 properties · 9 methods classComponentSelectMenu Utils Component Select Menu Structure 10 properties · 13 methods classComponentSelectMenuDefaultValue Utils Component Select Menu Option Structure 2 properties · 2 methods classComponentSelectMenuOption Utils Component Select Menu Option Structure 5 properties · 7 methods classComponentSeparator Utils Component Separator Structure 4 properties · 5 methods classComponentTextDisplay Utils Component Text Display Structure 3 properties · 4 methods classComponentThumbnail Utils Component Thumbnail Structure 5 properties · 6 methods classEmbed Utils Embed Structure 16 properties · 12 methods classEmbedAuthor Utils Embed Author Structure, used for [Embed] Structures 4 properties classEmbedField Utils Embed Field Structure, used for [Embed] Structures 3 properties classEmbedFooter Utils Embed Footer Structure, used for [Embed] Structures 3 properties classEmbedImage Utils Embed Image Structure, used for [Embed] Structures 4 properties classEmbedProvider Utils Provider Structure, used for [Embed] Structures 2 properties classEmbedThumbnail Utils Embed Thumbnail Structure, used for [Embed] Structures classEmbedVideo Utils Embed Video Structure, used for [Embed] Structures classInteractionModal The most basic Structure class, every structure extends this 5 properties · 19 methods classInteractionModalContext 56 properties · 12 methods

Interfaces

Object shapes for options, payloads and events.

Functions

Standalone helpers.

anyToCamelCase()

function src/utils/index.ts:92
function anyToCamelCase(object: any, skip?: string[]): any

diffNormalized()

function src/utils/applicationcommands.ts:145
function diffNormalized(a: any, b: any, path?: string): string[]

Deep compares two normalized payloads, returning the paths that differ (e.g. options[0:user].description)

a
any
b
any
path?
string
Default ''

generateWaveform()

function src/utils/index.ts:120
function generateWaveform(samples: Float32Array, sampleRate?: number): string
samples
Float32Array
sampleRate?
number
Default 48000

getFiles()

function async src/utils/index.ts:154
function getFiles(directory: string, subdirectories?: boolean): Promise<string[]>

getFirstArgument()

function src/utils/index.ts:244
function getFirstArgument(value: string): [string, string]

getFormatFromHash()

function src/utils/index.ts:192
function getFormatFromHash(
  hash: string,
  format?: string | null,
  defaultFormat?: string,
): string
hash
string
format?
string | null
defaultFormat?
string
Default ImageFormats.PNG

intToRGB()

function src/utils/index.ts:279
function intToRGB(int: number): { b: number; g: number; r: number }

normalizeLocalizations()

function src/utils/applicationcommands.ts:39
function normalizeLocalizations(
  value?: Record<string, string | undefined> | null,
): Record<string, string> | null

parseMentionsInText()

function src/utils/index.ts:292
function parseMentionsInText(
  context: Interaction | Message,
  content: string,
  options?: { escapeMentions?: boolean; guildSpecific?: boolean; nick?: boolean; text?: string },
): string
content
string
options?
{ escapeMentions?: boolean; guildSpecific?: boolean; nick?: boolean; text?: string }
options.escapeMentions?
boolean
options.guildSpecific?
boolean
options.nick?
boolean
options.text?
string

regex()

function src/utils/index.ts:431
function regex(
  regexName: string,
  content: string,
  onlyFirst?: boolean,
): DiscordRegexPayload
regexName
string
content
string
onlyFirst?
boolean
Default false

requireOrImport()

function async src/utils/index.ts:59
function requireOrImport(filepath: string): Promise<any>

Loads a command file with require() (its cache can be cleared, so reloading commands works) and falls back to import() for es modules require() can't load (like .mjs on older node, or ones with top-level await)

Type aliases

Named types used across the API.

Variables

Exported values.

KeyGenerator

variable const src/utils/index.ts:515
const KeyGenerator: Readonly<{ ApplicationCommand: (command: ApplicationCommand | InteractionCommand<…>) => string; ApplicationCommandOption: (option: InteractionCommandOption<…> | ApplicationCommandOption) => string; ApplicationCommandOptionChoice: (choice: InteractionCommandOptionChoice | ApplicationCommandOptionChoice) => string }>
export const KeyGenerator = Object.freeze({
  ApplicationCommand: (command: ApplicationCommand | InteractionCommand): string => {
    return [
      command.name,
      command.description,
      command.type,
      (command.options) ? command.options.map((x) => x.key).join(':') : '',
      JSON.stringify(normalizeLocalizations(command.descriptionLocalizations)),
      JSON.stringify(normalizeLocalizations(command.nameLocalizations)),
      command.defaultMemberPermissions,
      (command.dmPermission === undefined || command.dmPermission === null) ? true : !!command.dmPermission,
      normalizeContexts(command.contexts),
      normalizeIntegrationTypes(command.integrationTypes),
      Boolean(command.nsfw),
    ].join('-');
  },
  ApplicationCommandOption: (option: ApplicationCommandOption | InteractionCommandOption): string => {
    return [
      option.name,
      option.description,
      option.type,
      !!option.required,
      !!option.autocomplete,
      (option.options) ? option.options.map((x) => x.key).join(':') : '',
      (option.choices) ? option.choices.map((x) => x.key).join(':') : '',
      JSON.stringify(normalizeLocalizations(option.descriptionLocalizations)),
      JSON.stringify(normalizeLocalizations(option.nameLocalizations)),
      JSON.stringify(option.channelTypes),
      option.maxValue,
      option.minValue,
      option.maxLength,
      option.minLength,
    ].join('-');
  },
  ApplicationCommandOptionChoice: (choice: ApplicationCommandOptionChoice | InteractionCommandOptionChoice): string => {
    return `${choice.name}-${choice.value}-${typeof(choice.value)}-${JSON.stringify(normalizeLocalizations(choice.nameLocalizations))}`;
  },
});