2022-03-19 10:37:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
2022-03-24 10:55:32 +00:00
|
|
|
const BaseCommandInteraction = require('./BaseCommandInteraction');
|
|
|
|
const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver');
|
2022-03-19 10:37:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a command interaction.
|
2022-03-24 10:55:32 +00:00
|
|
|
* @extends {BaseCommandInteraction}
|
2022-03-19 10:37:45 +00:00
|
|
|
*/
|
2022-03-24 10:55:32 +00:00
|
|
|
class CommandInteraction extends BaseCommandInteraction {
|
2022-03-19 10:37:45 +00:00
|
|
|
constructor(client, data) {
|
|
|
|
super(client, data);
|
|
|
|
|
|
|
|
/**
|
2022-03-24 10:55:32 +00:00
|
|
|
* The options passed to the command.
|
|
|
|
* @type {CommandInteractionOptionResolver}
|
2022-03-19 10:37:45 +00:00
|
|
|
*/
|
2022-03-24 10:55:32 +00:00
|
|
|
this.options = new CommandInteractionOptionResolver(
|
|
|
|
this.client,
|
|
|
|
data.data.options?.map(option => this.transformOption(option, data.data.resolved)) ?? [],
|
|
|
|
this.transformResolved(data.data.resolved ?? {}),
|
|
|
|
);
|
2022-03-19 10:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-24 10:55:32 +00:00
|
|
|
* 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}
|
2022-03-19 10:37:45 +00:00
|
|
|
*/
|
2022-03-24 10:55:32 +00:00
|
|
|
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(' ')}`;
|
2022-03-19 10:37:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CommandInteraction;
|