feat(CommandInteraction): add toString method (#6793)

This commit is contained in:
Rodry
2021-10-12 20:11:18 +01:00
committed by GitHub
parent 5566404850
commit bd48e6df84
2 changed files with 16 additions and 0 deletions

View File

@@ -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
typings/index.d.ts vendored
View File

@@ -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 {