Idyst
DIAdiscord.js - Imagine an app
•Created by Idyst on 1/28/2024 in #djs-questions
TypeError: Cannot read properties of null (reading 'value') - [email protected]
I get the error spammed when I open the menu to select country.
module.exports = {
name: 'list',
description: "a",
type: ApplicationCommandType.ChatInput,
options: [
{
name: 'add',
description: 'a',
type: 1,
options: [
{
name: 'country',
description: 'Country',
type: 3,
required: true,
autocomplete: true
}
]
}
],
autocomplete: async (interaction, choices) => {
const focusedOption = interaction.options.getFocused(true);
if (focusedOption.name === 'country') {
choices = [
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
];
}
const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
let options;
if (filtered.length > 25) {
options = filtered.slice(0, 25);
} else {
options = filtered;
}
await interaction.respond(
options.map(choice => ({ name: choice, value: choice })),
);
},
run: async (client, interaction) => {
if (interaction.options._subcommand === 'add') {
const country = interaction.options.get('country').value;
// to be done
}
}
};
module.exports = {
name: 'list',
description: "a",
type: ApplicationCommandType.ChatInput,
options: [
{
name: 'add',
description: 'a',
type: 1,
options: [
{
name: 'country',
description: 'Country',
type: 3,
required: true,
autocomplete: true
}
]
}
],
autocomplete: async (interaction, choices) => {
const focusedOption = interaction.options.getFocused(true);
if (focusedOption.name === 'country') {
choices = [
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
];
}
const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
let options;
if (filtered.length > 25) {
options = filtered.slice(0, 25);
} else {
options = filtered;
}
await interaction.respond(
options.map(choice => ({ name: choice, value: choice })),
);
},
run: async (client, interaction) => {
if (interaction.options._subcommand === 'add') {
const country = interaction.options.get('country').value;
// to be done
}
}
};
46 replies