Getting a Type Error on getApplicationCommand function

Hello šŸ‘‹ I have been learning how to make a discord bot and wanted to make an advanced command + event handler. One of the things that I have found that I have to do is the getApplicationCommand.js function Here is the code for said file
module.exports = async (client, guildId) => {
let applicationCommands;

if (guildId) {
const guild = await client.guilds.fetch(guildId);
applicationCommands = guild.commands;
} else {
applicationCommands = await client.application.commands;
}

await applicationCommands.fetch();
return applicationCommands;
};
module.exports = async (client, guildId) => {
let applicationCommands;

if (guildId) {
const guild = await client.guilds.fetch(guildId);
applicationCommands = guild.commands;
} else {
applicationCommands = await client.application.commands;
}

await applicationCommands.fetch();
return applicationCommands;
};
For some reason, I get this error: TypeError: Cannot read properties of undefined (reading 'fetch') Any ideas?
13 Replies
d.js toolkit
d.js toolkitā€¢13mo ago
ā€¢ What's your exact discord.js npm list discord.js and node node -v version? ā€¢ Post the full error stack trace, not just the top part! ā€¢ Show your code! ā€¢ Explain what exactly your issue is. ā€¢ Not a discord.js issue? Check out #useful-servers.
Panda
Pandaā€¢13mo ago
discord.js@14.11.0 node version v18.12.1
treble/luna
treble/lunaā€¢13mo ago
on which fetch cann do you get the error
Panda
Pandaā€¢13mo ago
Bottom one await applicationCommands.fetch(); Any idea what this issue may be? Or maybe just a better way to implement the handler all together?
treble/luna
treble/lunaā€¢13mo ago
not really, but you can make a handler using your command files
Panda
Pandaā€¢13mo ago
I am doing this by following a tutorial by Under Ctrl, they do not experience this issue at all, so I'm pretty sure it has something to do with the discordjs version as he made the video 5 months ago ish
treble/luna
treble/lunaā€¢13mo ago
videos outdate pretty quickly, better to follow the guide
Panda
Pandaā€¢13mo ago
Alright I'll try to figure it out, moving on tho just a quick question, is there any way to create multipage modals? or do I have to make them submit the first one, and then send a prompt to open the next page?
treble/luna
treble/lunaā€¢13mo ago
yep
Panda
Pandaā€¢13mo ago
uh yep to the first part as in there is a way to do it, or yep to the 2nd part as in i have to do it the other way (doesn't really look nice)
treble/luna
treble/lunaā€¢13mo ago
yep to the second part, you'll have to show them a prompt also note that .showModal cannot be used on a ModalSubmitInteraction so you'll have to use commands / buttons etc
Panda
Pandaā€¢13mo ago
Yeah alrighty thankyou very much, I still need to figure out how to do the advanced command + event handler, if I do end up experiencing any more issues ill come back here ig šŸ˜„
d.js docs
d.js docsā€¢13mo ago
guide Creating Your Bot: Event handling read more