From bd48e6df844fd535949937c3603629413d422526 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Tue, 12 Oct 2021 20:11:18 +0100 Subject: [PATCH] feat(CommandInteraction): add toString method (#6793) --- src/structures/CommandInteraction.js | 15 +++++++++++++++ typings/index.d.ts | 1 + 2 files changed, 16 insertions(+) diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index 4c8bd5d75..c5dcfa2a3 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -21,6 +21,21 @@ class CommandInteraction extends BaseCommandInteraction { this.transformResolved(data.data.resolved ?? {}), ); } + + /** + * Returns a string representation of the command interaction. + * This can then be copied by a user and executed again in a new command while keeping the option order. + * @returns {string} + */ + toString() { + const properties = [ + this.commandName, + this.options._group, + this.options._subcommand, + ...this.options._hoistedOptions.map(o => `${o.name}:${o.value}`), + ]; + return `/${properties.filter(Boolean).join(' ')}`; + } } module.exports = CommandInteraction; diff --git a/typings/index.d.ts b/typings/index.d.ts index 8408dfbd6..8f79fbd2f 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -604,6 +604,7 @@ export type GuildCommandInteraction { public options: CommandInteractionOptionResolver; + public toString(): string; } export class CommandInteractionOptionResolver {