diff --git a/packages/builders/__tests__/messages/formatters.test.ts b/packages/builders/__tests__/messages/formatters.test.ts index 467cf547de53..6624ff11f8ce 100644 --- a/packages/builders/__tests__/messages/formatters.test.ts +++ b/packages/builders/__tests__/messages/formatters.test.ts @@ -2,6 +2,7 @@ import { URL } from 'node:url'; import { describe, test, expect, vitest } from 'vitest'; import { + chatInputApplicationCommandMention, blockQuote, bold, channelLink, @@ -137,6 +138,26 @@ describe('Message formatters', () => { expect(roleMention('815434166602170409')).toEqual('<@&815434166602170409>'); }); }); + + describe('chatInputApplicationCommandMention', () => { + test('GIVEN commandName and commandId THEN returns ""', () => { + expect(chatInputApplicationCommandMention('airhorn', '815434166602170409')).toEqual( + '', + ); + }); + + test('GIVEN commandName, subcommandName, and commandId THEN returns ""', () => { + expect(chatInputApplicationCommandMention('airhorn', 'sub', '815434166602170409')).toEqual( + '', + ); + }); + + test('GIVEN commandName, subcommandGroupName, subcommandName, and commandId THEN returns ""', () => { + expect(chatInputApplicationCommandMention('airhorn', 'group', 'sub', '815434166602170409')).toEqual( + '', + ); + }); + }); }); describe('formatEmoji', () => { diff --git a/packages/builders/src/messages/formatters.ts b/packages/builders/src/messages/formatters.ts index 2bbd50dd7e86..2d89d2ccdb3f 100644 --- a/packages/builders/src/messages/formatters.ts +++ b/packages/builders/src/messages/formatters.ts @@ -180,6 +180,75 @@ export function roleMention(roleId: C): `<@&${C}>` { return `<@&${roleId}>`; } +/** + * Formats an application command name, subcommand group name, subcommand name, and ID into an application command mention + * + * @param commandName - The application command name to format + * @param subcommandGroupName - The subcommand group name to format + * @param subcommandName - The subcommand name to format + * @param commandId - The application command ID to format + */ +export function chatInputApplicationCommandMention< + N extends string, + G extends string, + S extends string, + I extends Snowflake, +>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): ``; + +/** + * Formats an application command name, subcommand name, and ID into an application command mention + * + * @param commandName - The application command name to format + * @param subcommandName - The subcommand name to format + * @param commandId - The application command ID to format + */ +export function chatInputApplicationCommandMention( + commandName: N, + subcommandName: S, + commandId: I, +): ``; + +/** + * Formats an application command name and ID into an application command mention + * + * @param commandName - The application command name to format + * @param commandId - The application command ID to format + */ +export function chatInputApplicationCommandMention( + commandName: N, + commandId: I, +): ``; + +/** + * Formats an application command name, subcommand group name, subcommand name, and ID into an application command mention + * + * @param commandName - The application command name to format + * @param subcommandGroupName - The subcommand group name to format + * @param subcommandName - The subcommand name to format + * @param commandId - The application command ID to format + */ +export function chatInputApplicationCommandMention< + N extends string, + G extends Snowflake | string, + S extends Snowflake | string, + I extends Snowflake, +>( + commandName: N, + subcommandGroupName: G, + subcommandName?: S, + commandId?: I, +): `` | `` | `` { + if (typeof commandId !== 'undefined') { + return ``; + } + + if (typeof subcommandName !== 'undefined') { + return ``; + } + + return ``; +} + /** * Formats an emoji ID into a fully qualified emoji identifier * diff --git a/packages/discord.js/src/util/Formatters.js b/packages/discord.js/src/util/Formatters.js index 9d4c28240c92..7f3026811610 100644 --- a/packages/discord.js/src/util/Formatters.js +++ b/packages/discord.js/src/util/Formatters.js @@ -21,6 +21,17 @@ const { userMention, } = require('@discordjs/builders'); +/** + * Formats an application command name and id into an application command mention. + * @method chatInputApplicationCommandMention + * @param {string} commandName The name of the application command + * @param {string|Snowflake} subcommandGroupOrSubOrId + * The subcommand group name, subcommand name, or application command id + * @param {?(string|Snowflake)} [subcommandNameOrId] The subcommand name or application command id + * @param {?string} [commandId] The id of the application command + * @returns {string} + */ + /** * Wraps the content inside a code block with an optional language. * @method codeBlock