This only happens on some commands. Its JS anybody know how to fix it?
};
let cmd = this.commands.get(command);
if (cmd.SlashCommand && cmd.SlashCommand.run)
cmd.SlashCommand.run(this, interaction, args, { GuildDB });
});
2
Answers
Try interaction.commandName
My guess is that there might be some scoping issue utilizing "this"
If you are using discord.js you likely have client set up in index.js in your base directory, as well as attaching your commands via a command handler. For that reason, the following line will likely work:
The reason for this is that index.js declares the "client" as well as "client.commands":
… and later in index.js you call the command handler, specifying the folder structure your SlashCommand files are in…
… and your command handler is passed "client" as a prop via an anonymous method/function to populate "client.commands" and "client.commandArray":
If you utilize "client.commands" you likely will get more standard results.
The error message you’re encountering, "TypeError: Cannot read properties of undefined (reading ‘SlashCommand’)", indicates that the cmd object does not have a property called ‘SlashCommand’.
This error occurs when you attempt to access a property on an undefined or null value.
To troubleshoot this issue, you should check the following:
Make sure that the this.commands collection or map has been properly populated with command objects, and that the desired command exists within it.
Ensure that the command variable contains a valid command name.
Verify that the command object retrieved from this.commands.get(command) contains the expected properties.
Specifically, ensure that the cmd object has a property called ‘SlashCommand’.
Double-check your code to ensure that the command objects are being created and assigned to the this.commands collection correctly. It’s possible that the command object is not being assigned the ‘SlashCommand’ property during the initialization process.
By carefully reviewing your code and ensuring that the necessary properties and objects are properly defined and assigned, you should be able to resolve this error.
It’s better to provide more details to get a better answer.