TypeError: Cannot read properties of null (reading 'value') - discord.js@14.7.1

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
}
}
};
23 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
treble/luna
treble/luna5mo ago
Show the full error And update djs and dont access internal properties getSubcommand() exists
Idyst
Idyst5mo ago
my full code is: and error:
TypeError: Cannot read properties of null (reading 'value')
at Object.run (D:\bot\slashCommands\utility\order.js:215:65)
at Client.<anonymous> (D:\aaa\alky\smart-bot\events\interactionCreate.js:59:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
TypeError: Cannot read properties of null (reading 'value')
at Object.run (D:\bot\slashCommands\utility\order.js:215:65)
at Client.<anonymous> (D:\aaa\alky\smart-bot\events\interactionCreate.js:59:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
d.js docs
d.js docs5mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
treble/luna
treble/luna5mo ago
Your error probably is because there is no such options or it wasnt passed in And use getX(), x being the type you expect But still update djs because you will face more errors
Idyst
Idyst5mo ago
pastebin? i will try real quick like
const country = interaction.options.getString('country');
const country = interaction.options.getString('country');
?
Idyst
Idyst5mo ago
Pastebin
const { EmbedBuilder, ApplicationCommandType } = require('discord.j...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Idyst
Idyst5mo ago
<:i_couldnt_finish_the_project:586981416827617286>
treble/luna
treble/luna5mo ago
^
Idyst
Idyst5mo ago
it is here mate
Idyst
Idyst5mo ago
ok here is with getsubcommand() https://pastebin.com/jnNkyjBS
Pastebin
const { EmbedBuilder, ApplicationCommandType } = require('discord.j...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Idyst
Idyst5mo ago
alright, 1minute now when I try to open /order add I instantly get
D:\bot\slashCommands\utility\order.js:242
interaction.reply(`Order created! Order ID: #${data.id}`);
^

TypeError: interaction.reply is not a function
at Request._callback (D:\bot\slashCommands\utility\order.js:242:29)
at self.callback (D:\bot\node_modules\woocommerce-api\node_modules\request\request.js:185:22)
at Request.emit (node:events:513:28)
at Request.<anonymous> (D:\bot\node_modules\woocommerce-api\node_modules\request\request.js:1161:10)
at Request.emit (node:events:513:28)
at IncomingMessage.<anonymous> (D:\bot\node_modules\woocommerce-api\node_modules\request\request.js:1083:12)
at Object.onceWrapper (node:events:627:28)
at IncomingMessage.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.12.1
D:\bot\slashCommands\utility\order.js:242
interaction.reply(`Order created! Order ID: #${data.id}`);
^

TypeError: interaction.reply is not a function
at Request._callback (D:\bot\slashCommands\utility\order.js:242:29)
at self.callback (D:\bot\node_modules\woocommerce-api\node_modules\request\request.js:185:22)
at Request.emit (node:events:513:28)
at Request.<anonymous> (D:\bot\node_modules\woocommerce-api\node_modules\request\request.js:1161:10)
at Request.emit (node:events:513:28)
at IncomingMessage.<anonymous> (D:\bot\node_modules\woocommerce-api\node_modules\request\request.js:1083:12)
at Object.onceWrapper (node:events:627:28)
at IncomingMessage.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.12.1
thats after i added the method I changed
if (interaction.options._subcommand === 'info') {
if (interaction.options._subcommand === 'info') {
to
if (interaction.options.getSubcommand() === 'info') {
if (interaction.options.getSubcommand() === 'info') {
d.js docs
d.js docs5mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
Idyst
Idyst5mo ago
oh yea forgot, 1 second
Idyst
Idyst5mo ago
Pastebin
AutocompleteInteraction { type: 4, id: '1201564664451051551', ap...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Idyst
Idyst5mo ago
damn this autocomplete is so strange old non slash commands were easier ;d i see, tomorrow i will see what i can do to fix my issue i don't get why when i open the field which should pop up autocomplete suggestions it instantly execute the code and goes directly to line 242, like before it wasn't like that i am very confused I did few tests and noticed that this happens when I replace .value to like getString and etc
Idyst
Idyst5mo ago
i guess this is very bad way to do it but now i dont get error for value spammed, if you can help me with better solution I would highly appreciate it
No description
Idyst
Idyst5mo ago
https://sourceb.in/Lq2EtFVyWy i have done check for autocomplete
SourceBin
interactionCreate.js
Instantly share your code with the world.
d.js docs
d.js docs5mo ago
Checking for things to not be equal in JavaScript:
- if (!yourVariable === yourOtherVariable) // !yourVariable is coerced to a boolean value
+ if (yourVariable !== yourOtherVariable) // checks that one is not equal to the other
- if (!yourVariable === yourOtherVariable) // !yourVariable is coerced to a boolean value
+ if (yourVariable !== yourOtherVariable) // checks that one is not equal to the other
- Comparison operators in JavaScript: learn more
Idyst
Idyst5mo ago
so like
if (!interaction.type == 2) return;
if (!interaction.type == 2) return;
to
if (interaction.type !== 2) return;
if (interaction.type !== 2) return;
? thanks for that tip the only thing which i found is to ignore the error but that is not very good solution the change in the if helped, I can't use the method isAutocomplete because it is not function maybe because of djs version but just autocomplete works i will update it i see
Idyst
Idyst5mo ago
also I am not trying to jump from theme to theme but when i search for country which is not showing because it is sliced it don't find it
No description
Idyst
Idyst5mo ago
ohhh looks like the capital letters matter, I didn't know that I appreciate the help ,thanks so much I am going to update djs now should i mark the post as solved? thanks mate, have a nice night or day