UNPKG

commandbot

Version:

A framework that helps you create your own Discord bot easier.

58 lines (57 loc) 1.68 kB
/** * Object that stores all interaction input data (target, arguments, content and the interaction itself) * @class */ export class InputManager { /** * Command related to this manager * @type {FunctionCommand} * @public * @readonly */ command; /** * Command interaction or message * @type {Interaction | Message} * @public * @readonly */ interaction; /** * Command target (when using context menu interactions) * @type {?TargetID<any>} * @public * @readonly */ target; /** * All input arguments * @type {Array<InputParameter<any>>} * @private * @readonly */ arguments; /** * @constructor * @param {FunctionCommand} command - command related to this manager * @param {Interaction | Message} interaction - interaction or message * @param {Array<InputManager<any>>} args - list of input arguments * @param {?TargetID<any>} [target] - interaction target (when using context menu interactions) */ constructor(command, interaction, args, target) { this.command = command; this.interaction = interaction; this.arguments = args; this.target = target; } /** * Get input values * @param {string} query - parameter name * @param {T} type - parameter type * @returns {ParameterResolvable} Argument value bound to a parameter * @public */ get(query, type) { return this.arguments.filter((arg) => arg.type === type).find((arg) => arg.name === query)?.value ?? null; } }