Skip to content

Commit

Permalink
Fixed interactions and added the deferReply feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ION606 committed May 4, 2023
1 parent 90122ff commit b2573f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 6 additions & 4 deletions structures/interactions/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ModalComponent>}
*/
getComponents() {
const m = new Map();
Expand All @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions structures/interactions/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/interactionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit b2573f4

Please sign in to comment.