diff --git a/structures/interactions/Modal.js b/structures/interactions/Modal.js index 26a6d7d..aa3e8f7 100644 --- a/structures/interactions/Modal.js +++ b/structures/interactions/Modal.js @@ -68,15 +68,16 @@ export class Modal extends Interaction { * @returns {Boolean} true is added false otherwise */ addComponent(c) { - if (!c || this.components.has(c.custom_id)) return true; + if (!c || this.components.has(c.custom_id)) return false; this.components.set(c.custom_id, c); + return true; } /** * @description returns the Modal's components as a map of * * `custom_id ==> input` - * @returns {[{value: String, custom_id: String}]} + * @returns {Map} */ getComponents() { const m = new Map(); @@ -96,9 +97,10 @@ export class Modal extends Interaction { } toObj() { + if (this.components.size == 0) throw "MODAL MUST HAVE AT LEAST 1 COMPONENT!"; const obj = {title: this.title, custom_id: this.custom_id, components: []}; - for (const key in this.components) { - const comp = this.components.get(key); + + for (const [key, comp] of this.components) { const a = new MessageActionRow(); a.addComponent(comp); obj.components.push(a.toObj()); diff --git a/structures/interactions/interaction.js b/structures/interactions/interaction.js index 0957508..3ea5522 100644 --- a/structures/interactions/interaction.js +++ b/structures/interactions/interaction.js @@ -60,6 +60,16 @@ export class Interaction extends DataManager { /** @type {interactionOptions} */ data; + async deferReply() { + try { + await this.client.axiosCustom.post(`/interactions/${this.id}/${this.#token}/callback`, { + type: 5 + }); + } catch (err) { + console.log(err); + } + } + /** * @param {Modal} m */ diff --git a/tests/interactionTests.js b/tests/interactionTests.js index d194849..43e94ab 100644 --- a/tests/interactionTests.js +++ b/tests/interactionTests.js @@ -7,8 +7,8 @@ const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); /** @param {Interaction} interaction */ export default async (interaction) => { if (interaction.type == interactionTypes.ApplicationCommand) { - console.log(interaction.data); + return interaction.deferReply(); const m = new Modal(null, interaction.client); const c = new ModalComponent(); c.custom_id = 'nonononononono';