modals-eris
Version:
Create Modals using the Discord API. Focused on Eris library.
28 lines (25 loc) • 1.11 kB
JavaScript
const axios = require('axios');
async function createModal(interaction, modalData) {
if(!interaction) throw new Error('[ERIS_MODALS ERROR] I need an interaction to create the Modal.');
if(!interaction.token || !interaction.id) throw new Error('[ERIS_MODALS ERROR] I need a valid Interaction to create the Modal.');
if(!modalData) throw new Error('[ERIS_MODALS ERROR] You need to include the modal Object.');
if(typeof(modalData) != 'object') throw new Error('[ERIS_MODALS ERROR] The Modal must be an Object.');
try {
await axios({
method: 'POST',
url: `https://discord.com/api/interactions/${interaction.id}/${interaction.token}/callback`,
headers: {
Authorization: `Bot ${interaction.token}`,
},
data: {
type: 9,
data: modalData,
},
}).catch((e) => {
throw new Error(e.message);
});
} catch (err) {
throw new Error('[ERIS_MODALS ERROR] ' + err.message)
};
};
module.exports = { createModal };