UNPKG

hytescript.js

Version:

A package for programming anything you want with ease.

43 lines (35 loc) 1.57 kB
const { clone, Functions } = require("../../utils/utils"); module.exports = { description: 'Responds to autocomplete interaction.', usage: 'choices', parameters: [ { name: 'Choices', description: 'A builder parameter; sets the choices to be sent.', optional: 'false', defaultValue: 'none' } ], dontParse: [0], run: async (d, choices) => { if (!['interaction', 'autocompleteInteraction'].includes(d.eventType)) return new d.error("notAllowed", d, 'interaction or autocompleteInteraction types') if (choices == undefined) return new d.error("required", d, 'choices') if (d.interaction.responded) return new d.error("custom", d, 'that interaction already have been respoded') const responseChoices = [] let choicesData = clone(d) choicesData.functions = new Functions(choicesData.functions).set('setchoice', { code: async (d, name, value) => { if (name == undefined) return new d.error("required", d, 'name') if (value == undefined) return new d.error("required", d, 'value') responseChoices.push({ name, value }) } }) await choices.parse(choicesData, true) d.err = choicesData.err if (d.err) return; d.data = choicesData.data await d.interaction.respond(responseChoices).catch(e => new d.error('custom', d, e.message)) } };