I am getting this error when the snippet is right.

Hello! I am making a bot, very complex handling system which works perfectly, until now... I have made a command and yet it doesn't work, check the error and snippets below.
There was an error running this command: TypeError: interaction.options.getSubcommand is not a function.
There was an error running this command: TypeError: interaction.options.getSubcommand is not a function.
name: 'order',
description: '-',
options: [
{
name: 'start',
description: 'Begin the order process, this will notify your customer you are beginning.',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'id',
description: 'The ID provided when you prepared the order. Lost it? Check your DMs, the ID will be provided there.',
type: ApplicationCommandOptionType.Number,
required: true,
}
]
},
{
name: 'prepare',
description: 'Prepare your order, add the price, includes the notes.',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'customer',
description: 'Client of this order.',
type: ApplicationCommandOptionType.User,
required: true,
},
{
name: 'price',
description: 'The price of the order before tax.',
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: 'duration',
description: 'Estimated duration of the order. Use terms like: 1w for 1 week, 1d for 1 day, 1m for 1 month.',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'references',
description: 'You have the option to attach any references the designer added.',
type: ApplicationCommandOptionType.Attachment,
required: false,
},
{
name: 'notes',
description: 'Add any additional notes you may need here!',
type: ApplicationCommandOptionType.String,
required: false,
},
],
},
{
name: 'update',
description: 'Update your client on the order status.',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'id',
description: 'The ID provided when you prepared the order. Lost it? Check your DMs, the ID will be provided there.',
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: 'status',
description: 'Select one of our status updates for your order.',
type: ApplicationCommandOptionType.String,
required: true,
choices: [
{
name: 'Preparing the Order',
value: 'order-prep'
},
{
name: 'Designing Product(s)',
value: 'designing-product'
},
{
name: 'Product(s) in QC',
value: 'qc-products'
},
],
},
],
},
{
name: 'complete',
description: 'Complete a current order, this will notify your client of completion.',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'id',
description: 'The ID provided when you prepared the order. Lost it? Check your DMs, the ID will be provided there.',
type: ApplicationCommandOptionType.Number,
required: true
},
{
name: 'proof',
description: 'Purchase proof from the roblox store/other provider.',
type: ApplicationCommandOptionType.Attachment,
required: false,
},
],
},
],
name: 'order',
description: '-',
options: [
{
name: 'start',
description: 'Begin the order process, this will notify your customer you are beginning.',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'id',
description: 'The ID provided when you prepared the order. Lost it? Check your DMs, the ID will be provided there.',
type: ApplicationCommandOptionType.Number,
required: true,
}
]
},
{
name: 'prepare',
description: 'Prepare your order, add the price, includes the notes.',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'customer',
description: 'Client of this order.',
type: ApplicationCommandOptionType.User,
required: true,
},
{
name: 'price',
description: 'The price of the order before tax.',
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: 'duration',
description: 'Estimated duration of the order. Use terms like: 1w for 1 week, 1d for 1 day, 1m for 1 month.',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'references',
description: 'You have the option to attach any references the designer added.',
type: ApplicationCommandOptionType.Attachment,
required: false,
},
{
name: 'notes',
description: 'Add any additional notes you may need here!',
type: ApplicationCommandOptionType.String,
required: false,
},
],
},
{
name: 'update',
description: 'Update your client on the order status.',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'id',
description: 'The ID provided when you prepared the order. Lost it? Check your DMs, the ID will be provided there.',
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: 'status',
description: 'Select one of our status updates for your order.',
type: ApplicationCommandOptionType.String,
required: true,
choices: [
{
name: 'Preparing the Order',
value: 'order-prep'
},
{
name: 'Designing Product(s)',
value: 'designing-product'
},
{
name: 'Product(s) in QC',
value: 'qc-products'
},
],
},
],
},
{
name: 'complete',
description: 'Complete a current order, this will notify your client of completion.',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'id',
description: 'The ID provided when you prepared the order. Lost it? Check your DMs, the ID will be provided there.',
type: ApplicationCommandOptionType.Number,
required: true
},
{
name: 'proof',
description: 'Purchase proof from the roblox store/other provider.',
type: ApplicationCommandOptionType.Attachment,
required: false,
},
],
},
],
That is the command being initialized.
callback: async (interaction, client) => {
const subcommand = interaction.options.getSubcommand()
const member = interaction.member
const designerRole = ServerConfig && ServerConfig.orderRole
...
}
callback: async (interaction, client) => {
const subcommand = interaction.options.getSubcommand()
const member = interaction.member
const designerRole = ServerConfig && ServerConfig.orderRole
...
}
This is the code for the command, it is in the testing stage.
8 Replies
d.js toolkit
d.js toolkit2mo 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 staff
tate.b
tate.bOP2mo ago
14.16.3 20.18.03
duck
duck2mo ago
could you show where you call the function callback?
tate.b
tate.bOP2mo ago
yes Would it be easier if I were to say I have many subcommand commands and it always works, this is an odd case or do you need to see it?
duck
duck2mo ago
I'd still like to see it
tate.b
tate.bOP2mo ago
Okay!
const { REST, Routes } = require('discord.js');
const { devs, testServer, clientId } = require("../../../config.json");
const getLocalCommands = require("../../utils/getLocalCommands");

module.exports = async (client, interaction) => {


// Register commands on startup
/*if (!client.commandsRegistered) {
const localCommands = getLocalCommands();

const commands = localCommands.map((cmd) => ({
name: cmd.name,
description: cmd.description,
options: cmd.options || [],
default_permission: true,
}));

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationCommands(clientId), // For global commands
// Routes.applicationGuildCommands(clientId, testServer), // Uncomment this for guild-specific commands
{ body: commands }
);

console.log('Successfully reloaded application (/) commands.');
client.commandsRegistered = true; // Mark as registered to avoid re-registering
} catch (error) {
console.error('Error registering commands globally:', error);
}
}*/

// Handle modals and select menus


// Handle slash commands
if (!interaction.isChatInputCommand()) return;

const localCommands = getLocalCommands();

try {
const commandObject = localCommands.find(
(cmd) => cmd.name === interaction.commandName
);

if (!commandObject) return;

if (commandObject.devOnly) {
if (!devs.includes(interaction.member.id)) {
interaction.reply({
content: "Only developers are allowed to run this command.",
ephemeral: true,
});
return;
}
}

if (commandObject.testOnly) {
if (!(interaction.guild.id === testServer)) {
interaction.reply({
content: "This command cannot be ran here.",
ephemeral: true,
});
return;
}
}

if (commandObject.permissionsRequired?.length) {
for (const permission of commandObject.permissionsRequired) {
if (!interaction.member.permissions.has(permission)) {
interaction.reply({
content: "Not enough permissions.",
ephemeral: true,
});
return;
}
}
}

if (commandObject.botPermissions?.length) {
for (const permission of commandObject.botPermissions) {
const bot = interaction.guild.members.me;

if (!bot.permissions.has(permission)) {
interaction.reply({
content: "Designy doesn't have enough permissions to run this command.",
ephemeral: true,
});
return;
}
}
}


await commandObject.callback(client, interaction);

} catch (error) {
console.log(`There was an error running this command: ${error}.`);
}
};
const { REST, Routes } = require('discord.js');
const { devs, testServer, clientId } = require("../../../config.json");
const getLocalCommands = require("../../utils/getLocalCommands");

module.exports = async (client, interaction) => {


// Register commands on startup
/*if (!client.commandsRegistered) {
const localCommands = getLocalCommands();

const commands = localCommands.map((cmd) => ({
name: cmd.name,
description: cmd.description,
options: cmd.options || [],
default_permission: true,
}));

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationCommands(clientId), // For global commands
// Routes.applicationGuildCommands(clientId, testServer), // Uncomment this for guild-specific commands
{ body: commands }
);

console.log('Successfully reloaded application (/) commands.');
client.commandsRegistered = true; // Mark as registered to avoid re-registering
} catch (error) {
console.error('Error registering commands globally:', error);
}
}*/

// Handle modals and select menus


// Handle slash commands
if (!interaction.isChatInputCommand()) return;

const localCommands = getLocalCommands();

try {
const commandObject = localCommands.find(
(cmd) => cmd.name === interaction.commandName
);

if (!commandObject) return;

if (commandObject.devOnly) {
if (!devs.includes(interaction.member.id)) {
interaction.reply({
content: "Only developers are allowed to run this command.",
ephemeral: true,
});
return;
}
}

if (commandObject.testOnly) {
if (!(interaction.guild.id === testServer)) {
interaction.reply({
content: "This command cannot be ran here.",
ephemeral: true,
});
return;
}
}

if (commandObject.permissionsRequired?.length) {
for (const permission of commandObject.permissionsRequired) {
if (!interaction.member.permissions.has(permission)) {
interaction.reply({
content: "Not enough permissions.",
ephemeral: true,
});
return;
}
}
}

if (commandObject.botPermissions?.length) {
for (const permission of commandObject.botPermissions) {
const bot = interaction.guild.members.me;

if (!bot.permissions.has(permission)) {
interaction.reply({
content: "Designy doesn't have enough permissions to run this command.",
ephemeral: true,
});
return;
}
}
}


await commandObject.callback(client, interaction);

} catch (error) {
console.log(`There was an error running this command: ${error}.`);
}
};
This is my command handler file, the callback is at the bottom. It is run mostly on objects
d.js docs
d.js docs2mo ago
The order of function parameters must match between definition and function call.
function execute(client, interaction) { ... };
execute(interaction, client);
function execute(client, interaction) { ... };
execute(interaction, client);
- mismatch! you pass an interaction where the client is expected - mismatch! you pass the client where an interaction is expected
tate.b
tate.bOP2mo ago
You are amazing!! Thanks for helping me! It works now
Want results from more Discord servers?
Add your server