addQuery()
function src/utils/index.ts:135function addQuery(url: string, query?: UrlQuery): stringBuilders for embeds, components and modals, plus markup, permission and regex helpers.
import { Utils } from 'detritus-client';Grouped exports, reached as properties of the package.
Classes you create or receive from the library.
Object shapes for options, payloads and events.
Standalone helpers.
function addQuery(url: string, query?: UrlQuery): stringfunction anyToCamelCase(object: any, skip?: string[]): anyfunction createComponentListenerOrNone(
options?: string | CreateComponentListenerOrNone,
id?: string,
): [string, Components | null, boolean] | nullfunction diffApplicationCommands(
local: InteractionCommand,
remote: ApplicationCommand,
options?: NormalizeApplicationCommandOptions,
): string[]Returns the fields that differ between our local command and the one Discord has stored, empty if they match
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)
function generateWaveform(samples: Float32Array, sampleRate?: number): stringfunction getAcronym(name?: string): stringfunction getAttachmentUrlExpiry(url: string): numberUnix ms of when a signed attachment url expires, 0 if it has no (valid hex) ex query parameter
function getFiles(directory: string, subdirectories?: boolean): Promise<string[]>function getFirstArgument(value: string): [string, string]function getFormatFromHash(
hash: string,
format?: string | null,
defaultFormat?: string,
): stringfunction hexToInt(hex: string): numberfunction importFilesIn(
directory: string,
subdirectories: boolean,
reload?: boolean,
): Promise<{ errors: Record<string, Error>; files: ImportedFile[] }>Imports every command file in a directory, yielding every few ms since a sync require() loop blocks the event loop
function intToHex(int: number, hashtag?: boolean): stringfunction intToRGB(int: number): { b: number; g: number; r: number }function isValidAttachmentUrl(url: string): booleanIf an attachment url is signed (ex, is and a 64 character hm, all hex) and hasn't expired yet. Only the format is checked, the hm signature itself can only be verified by discord
function normalizeApplicationCommand(
command: ApplicationCommandLike,
options?: NormalizeApplicationCommandOptions,
): Record<string, any>Normalizes a local or remote command into the same payload shape, so equivalent commands are deeply equal
function normalizeApplicationCommandOption(
option: ApplicationCommandOptionLike,
): Record<string, any>function normalizeApplicationCommandOptionChoice(
choice: ApplicationCommandOptionChoiceLike,
): Record<string, any>function normalizeContexts(
value?: InteractionContextTypes[] | null,
): InteractionContextTypes[] | nullfunction normalizeIntegrationTypes(
value?: ApplicationIntegrationTypes[] | null,
): ApplicationIntegrationTypes[] | nullfunction normalizeLocalizations(
value?: Record<string, string | undefined> | null,
): Record<string, string> | nullfunction parseMentionsInText(
context: Interaction | Message,
content: string,
options?: { escapeMentions?: boolean; guildSpecific?: boolean; nick?: boolean; text?: string },
): stringfunction regex(
regexName: string,
content: string,
onlyFirst?: boolean,
): DiscordRegexPayloadfunction requireOrImport(filepath: string, reload?: boolean): Promise<any>Loads with require() so its cache can be cleared on reload, falling back to import() for es modules it can't load
function rgbToInt(r: number, g: number, b: number): numberfunction toCamelCase(value: string): stringNamed types used across the API.
type ApplicationCommandLike = ApplicationCommand | InteractionCommandtype ApplicationCommandOptionChoiceLike = ApplicationCommandOptionChoice | InteractionCommandOptionChoicetype ApplicationCommandOptionLike = ApplicationCommandOption | InteractionCommandOptiontype ComponentActionRowChild = ComponentButton | ComponentInputText | ComponentOverflowMenu | ComponentSelectMenutype ComponentEmojiData = { animated?: boolean; id?: null | string; name: string } | string | Emojitype ComponentLabelChild = ComponentCheckbox | ComponentCheckboxGroup | ComponentFileUpload | ComponentInputText | ComponentRadioGroup | ComponentSelectMenutype ComponentOnError = (context: ComponentContext, error: Error) => unknowntype ComponentOnTimeout = () => unknowntype ComponentRun = (context: ComponentContext) => unknowntype DiscordRegexPayload = DiscordRegexPayloadEmoji | DiscordRegexPayloadGuildNavigation | DiscordRegexPayloadJumpChannel | DiscordRegexPayloadJumpChannelMessage | DiscordRegexPayloadMentionChannelOrRole | DiscordRegexPayloadMentionCommand | DiscordRegexPayloadMentionUser | DiscordRegexPayloadSoundboardSound | DiscordRegexPayloadTextCodeblock | DiscordRegexPayloadTextGeneric | DiscordRegexPayloadTextHeader | DiscordRegexPayloadTextSubtext | DiscordRegexPayloadTimestamptype InteractionModalArgs = Record<string, any>type InteractionModalOnError = (context: InteractionModalContext, args: InteractionModalArgs, error: Error) => unknowntype InteractionModalOnTimeout = () => unknowntype InteractionModalRun = (context: InteractionModalContext, args: InteractionModalArgs) => unknowntype Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>type UrlQuery = Record<string, any>Exported values.
const IMPORT_YIELD_INTERVAL: 10 = 10const 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))}`;
},
});