Passing an external arrays as command option choices.

I am trying to figure out how I can pass an external array through module exports into my command file. My Command File:
const { EmbedBuilder, ApplicationCommandOptionType, ApplicationCommandType } = require("discord.js")
const { mysql, connection } = require('../../../../bot')
const { items } = require('../../../Functions/shopItems')
module.exports = {
name: "buy",
type: ApplicationCommandType.ChatInput,
description: "Buy Items from the in-game shop.",
options: [
{
name: "item",
description: "The name of the item you would like to buy",
type: ApplicationCommandOptionType.String,
choices: [items]
}
],
run: async(DiscordClient, interaction) => {
try {
await interaction.deferReply();
const user = interaction.options.getUser("user");
var userId = interaction.user.id;
var account_balance = "";
connection.query(`SELECT * FROM economy_accounts WHERE user_id = "786521239560519712";`, function(error, results) {
if (error) {
console.log(error)
interaction.editReply("Sorry, something went wrong, please contact the developer if this issue persists.")
} else {
interaction.editReply(`Your account balance is: ${results[0]["account_balance"]}`)
}
})
console.log(items)
} catch (error) {
console.log(error)
}
}
}
const { EmbedBuilder, ApplicationCommandOptionType, ApplicationCommandType } = require("discord.js")
const { mysql, connection } = require('../../../../bot')
const { items } = require('../../../Functions/shopItems')
module.exports = {
name: "buy",
type: ApplicationCommandType.ChatInput,
description: "Buy Items from the in-game shop.",
options: [
{
name: "item",
description: "The name of the item you would like to buy",
type: ApplicationCommandOptionType.String,
choices: [items]
}
],
run: async(DiscordClient, interaction) => {
try {
await interaction.deferReply();
const user = interaction.options.getUser("user");
var userId = interaction.user.id;
var account_balance = "";
connection.query(`SELECT * FROM economy_accounts WHERE user_id = "786521239560519712";`, function(error, results) {
if (error) {
console.log(error)
interaction.editReply("Sorry, something went wrong, please contact the developer if this issue persists.")
} else {
interaction.editReply(`Your account balance is: ${results[0]["account_balance"]}`)
}
})
console.log(items)
} catch (error) {
console.log(error)
}
}
}
shopItems list
module.exports = {
items: [
{ name: "Pen", value: "pen" },
{ name: "Book", value: "book" }
]
}
module.exports = {
items: [
{ name: "Pen", value: "pen" },
{ name: "Book", value: "book" }
]
}
DiscordAPIError[50035]: Invalid Form Body options[0].choices[0][LIST_ITEM_VALUE_REQUIRED]: List item values of ModelType are required
4 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MrMythical
MrMythical2y ago
if items is an array, then you are nesting arrays btw, sounds like autocomplete is a better option here
Noxxe
NoxxeOP2y ago
I have tried auto complete, I am not sure how I would go about doing it because I would need to set up the function outside of the async module/container. Sorry, I am not too advanced on JavaScript as of yet, is there any possibility that you can elaborate on that a tiny bit. Ahh okay, that's perfectly understand, thanks for the input! Both of you!
Want results from more Discord servers?
Add your server