Guys pls someone help me with this i am writing i wanna put slash commands to my bot but i cant
TypeError: Cannot read properties of undefined (reading 'cache') its discord.js v14
const guild = client.guild.cache.get(guildId)
if (!guild) {
console.error(
Guild with the ${guild} was not found
);
}
guild.commands.set(commands).catch((error => {
console.error(error setting commands for guild ${guild.name} (${guild.id}):
, error);
}));
}
client.on('interactionCreate', async (Interaction) => {
try {
if(Interaction.CommandName === 'mimic') {
const mimic = interaction.options.getString('say');
await interaction.reply(you said: \n${mimic}
);
}
} catch (error) {
console.error(error);
}
})18 Replies
- 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!its client.guilds
it work but now its saying this
error setting commands for guild Ghost RolePlay (842396705207091220): DiscordAPIError[50035]: Invalid Form Body
0.options[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (5, 4, 11, 2, 3, 7, 9, 8, 10, 6, 1).
One of your command options doesnt have a type
and dont deploy your commands on startup
Use the separate rest script
what do you mean saperate rest script
.
how do i fix that
oh ok
by specifying a type, and also showing the actual code
i saw it
what do you mean specifiyng a type i am new to djs
then please read the guide
and docs
ok
i write the deployment script in the deploy-commands.js right?
yes
does the deploy command file need to be in a commands folder?
it says that it cant find the module
it expects you to have your commands in subfolders yes
you can adjust the path to your environment
ok so i created a commands folder and i put the file there and now how do i adjust the path
do i const it on index.js
?
you edit the path in your code
or you make a commands folder with subfolders