Skip to content

Commit

Permalink
feat(CommandInteraction): add toString method (#6793)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Oct 12, 2021
1 parent 5566404 commit bd48e6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/structures/CommandInteraction.js
Expand Up @@ -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;
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -604,6 +604,7 @@ export type GuildCommandInteraction<Cached extends GuildCacheState = GuildCacheS

export class CommandInteraction extends BaseCommandInteraction implements GuildCachedInteraction<CommandInteraction> {
public options: CommandInteractionOptionResolver;
public toString(): string;
}

export class CommandInteractionOptionResolver {
Expand Down

0 comments on commit bd48e6d

Please sign in to comment.