diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index 4c8bd5d7535a..c5dcfa2a3fd7 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 3bd0b3dfcf15..b73f3ba27016 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -603,6 +603,7 @@ export type GuildCommandInteraction { public options: CommandInteractionOptionResolver; + public toString(): string; } export class CommandInteractionOptionResolver {