addQuery()
function src/utils/index.ts:72function 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 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 intToHex(int: number, hashtag?: boolean): stringfunction intToRGB(int: number): { b: number; g: number; r: number }function normalizeApplicationCommand(
command: ApplicationCommandLike,
options?: NormalizeApplicationCommandOptions,
): Record<string, any>Converts a local or remote command into the same plain payload shape, with defaults filled in and empty values collapsed, so that two equivalent commands produce deeply-equal objects
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): 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)
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 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 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 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))}`;
},
});