Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CommandInteraction): add toString method #6793

Merged
merged 2 commits into from Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -603,6 +603,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