@wilcosp/rex
Version:
Rex is an automated command manager for discord js
63 lines (62 loc) • 1.85 kB
JavaScript
/*!
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { BaseSelectMenuBuilder } from "discord.js";
import { checkCustomId } from "../multiUse/component.js";
export class RexSelectMenuBase extends BaseSelectMenuBuilder {
constructor(data, type) {
if (typeof data == "string") {
data = {
custom_id: data,
};
}
checkCustomId(data.custom_id);
super({ ...data, type });
this.deferEphemeral = false;
}
get customId() {
return this.data.custom_id;
}
setAutoDefer(defer, ephemeral = false) {
this.autoDefer = defer;
this.deferEphemeral = ephemeral;
return this;
}
setDebounceDelay(delay) {
this.debounceDelay = delay;
return this;
}
setAuditDelay(delay) {
this.auditDelay = delay;
return this;
}
setUseFailOver(value) {
this.useFailover = value;
return this;
}
setExecute(fun) {
this.execute = fun;
return this;
}
run(inter, use) {
if (this.execute) {
return this.execute.apply(null, [
new use(inter, {
autoDefer: this.autoDefer,
deferEphemeral: this.deferEphemeral,
debounceDelay: this.debounceDelay,
auditDelay: this.auditDelay,
useFailOver: this.useFailover,
}),
]);
}
}
toJSON() {
if (!this.execute) {
throw TypeError(`${this.customId}-${this.data.type} requires an execute function to be registered`);
}
return super.toJSON();
}
}