fix(sendSlash): Error with options

fixed #235
This commit is contained in:
March 7th 2022-08-03 21:37:10 +07:00
parent 34277d93f0
commit 855387a1da

View File

@ -628,10 +628,10 @@ class ApplicationCommand extends Base {
option_[0] = { option_[0] = {
type: ApplicationCommandOptionTypes[subCommand.type], type: ApplicationCommandOptionTypes[subCommand.type],
name: subCommand.name, name: subCommand.name,
options: optionFormat.filter(obj => obj.value !== undefined), options: optionFormat,
}; };
} else { } else {
option_ = optionFormat.filter(obj => obj.value !== undefined); option_ = optionFormat;
} }
// Autoresponse // Autoresponse
const getAutoResponse = async (options_, type, name, value) => { const getAutoResponse = async (options_, type, name, value) => {
@ -703,7 +703,7 @@ class ApplicationCommand extends Base {
if (this.options[i].choices && this.options[i].choices.length > 0) { if (this.options[i].choices && this.options[i].choices.length > 0) {
choice = choice =
this.options[i].choices.find(c => c.name == value) || this.options[i].choices.find(c => c.value == value); this.options[i].choices.find(c => c.name == value) || this.options[i].choices.find(c => c.value == value);
if (!choice && value) { if (!choice && value !== undefined) {
throw new Error( throw new Error(
`Invalid option: ${value} is not a valid choice for this option\nList of choices:\n${this.options[ `Invalid option: ${value} is not a valid choice for this option\nList of choices:\n${this.options[
i i
@ -717,9 +717,7 @@ class ApplicationCommand extends Base {
type: ApplicationCommandOptionTypes[this.options[i].type], type: ApplicationCommandOptionTypes[this.options[i].type],
name: this.options[i].name, name: this.options[i].name,
value: value:
choice?.value || value == undefined choice?.value || this.options[i].type == 'ATTACHMENT'
? value
: this.options[i].type == 'ATTACHMENT'
? await addDataFromAttachment(value) ? await addDataFromAttachment(value)
: this.options[i].type == 'INTEGER' : this.options[i].type == 'INTEGER'
? Number(value) ? Number(value)
@ -734,7 +732,7 @@ class ApplicationCommand extends Base {
) )
: value, : value,
}; };
optionFormat.push(data); if (value !== undefined) optionFormat.push(data);
} else { } else {
// First element is sub command and removed // First element is sub command and removed
if (!value) continue; if (!value) continue;
@ -744,7 +742,7 @@ class ApplicationCommand extends Base {
choice = choice =
subCommand.options[i].choices.find(c => c.name == value) || subCommand.options[i].choices.find(c => c.name == value) ||
subCommand.options[i].choices.find(c => c.value == value); subCommand.options[i].choices.find(c => c.value == value);
if (!choice && value) { if (!choice && value !== undefined) {
throw new Error( throw new Error(
`Invalid option: ${value} is not a valid choice for this option\nList of choices: \n${subCommand.options[ `Invalid option: ${value} is not a valid choice for this option\nList of choices: \n${subCommand.options[
i i
@ -758,9 +756,7 @@ class ApplicationCommand extends Base {
type: ApplicationCommandOptionTypes[subCommand.options[i].type], type: ApplicationCommandOptionTypes[subCommand.options[i].type],
name: subCommand.options[i].name, name: subCommand.options[i].name,
value: value:
choice?.value || value == undefined choice?.value || subCommand.options[i].type == 'ATTACHMENT'
? value
: subCommand.options[i].type == 'ATTACHMENT'
? await addDataFromAttachment(value) ? await addDataFromAttachment(value)
: subCommand.options[i].type == 'INTEGER' : subCommand.options[i].type == 'INTEGER'
? Number(value) ? Number(value)
@ -775,7 +771,7 @@ class ApplicationCommand extends Base {
) )
: value, : value,
}; };
optionFormat.push(data); if (value !== undefined) optionFormat.push(data);
} }
} }
if (!subCommandCheck && this.options[i]?.required) { if (!subCommandCheck && this.options[i]?.required) {
@ -785,6 +781,7 @@ class ApplicationCommand extends Base {
throw new Error('Value required missing'); throw new Error('Value required missing');
} }
let nonce = SnowflakeUtil.generate(); let nonce = SnowflakeUtil.generate();
console.log(option_);
const data = { const data = {
type: 2, // Slash command, context menu type: 2, // Slash command, context menu
// Type: 4: Auto-complete // Type: 4: Auto-complete