mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-05-15 06:36:55 +00:00
Fixed interactions and added the deferReply feature
This commit is contained in:
@@ -68,15 +68,16 @@ export class Modal extends Interaction {
|
|||||||
* @returns {Boolean} true is added false otherwise
|
* @returns {Boolean} true is added false otherwise
|
||||||
*/
|
*/
|
||||||
addComponent(c) {
|
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);
|
this.components.set(c.custom_id, c);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description returns the Modal's components as a map of
|
* @description returns the Modal's components as a map of
|
||||||
*
|
*
|
||||||
* `custom_id ==> input`
|
* `custom_id ==> input`
|
||||||
* @returns {[{value: String, custom_id: String}]}
|
* @returns {Map<String, ModalComponent>}
|
||||||
*/
|
*/
|
||||||
getComponents() {
|
getComponents() {
|
||||||
const m = new Map();
|
const m = new Map();
|
||||||
@@ -96,9 +97,10 @@ export class Modal extends Interaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toObj() {
|
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: []};
|
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();
|
const a = new MessageActionRow();
|
||||||
a.addComponent(comp);
|
a.addComponent(comp);
|
||||||
obj.components.push(a.toObj());
|
obj.components.push(a.toObj());
|
||||||
|
|||||||
@@ -60,6 +60,16 @@ export class Interaction extends DataManager {
|
|||||||
/** @type {interactionOptions} */
|
/** @type {interactionOptions} */
|
||||||
data;
|
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
|
* @param {Modal} m
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|||||||
/** @param {Interaction} interaction */
|
/** @param {Interaction} interaction */
|
||||||
export default async (interaction) => {
|
export default async (interaction) => {
|
||||||
if (interaction.type == interactionTypes.ApplicationCommand) {
|
if (interaction.type == interactionTypes.ApplicationCommand) {
|
||||||
console.log(interaction.data);
|
|
||||||
|
|
||||||
|
return interaction.deferReply();
|
||||||
const m = new Modal(null, interaction.client);
|
const m = new Modal(null, interaction.client);
|
||||||
const c = new ModalComponent();
|
const c = new ModalComponent();
|
||||||
c.custom_id = 'nonononononono';
|
c.custom_id = 'nonononononono';
|
||||||
|
|||||||
Reference in New Issue
Block a user