command.execute is not a function

Error
TypeError: command.execute is not a function
at Object.execute (/workspace/official-realtrickz-community-bot/src/events/client/interactionCreate.js:11:31)
at Client.<anonymous> (/workspace/official-realtrickz-community-bot/src/functions/handlers/handleEvents.js:15:63)
at Client.emit (node:events:514:28)
at InteractionCreateAction.handle (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/workspace/official-realtrickz-community-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/workspace/official-realtrickz-community-bot/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/workspace/official-realtrickz-community-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
TypeError: command.execute is not a function
at Object.execute (/workspace/official-realtrickz-community-bot/src/events/client/interactionCreate.js:11:31)
at Client.<anonymous> (/workspace/official-realtrickz-community-bot/src/functions/handlers/handleEvents.js:15:63)
at Client.emit (node:events:514:28)
at InteractionCreateAction.handle (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/workspace/official-realtrickz-community-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/workspace/official-realtrickz-community-bot/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/workspace/official-realtrickz-community-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
66 Replies
d.js toolkit
d.js toolkit10mo 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!
treble/luna
treble/luna10mo ago
well show your command
EdwardD
EdwardD10mo ago
I got this, was just working with this guy in v14 help
CoderZen
CoderZen10mo ago
it happens everytime i run a command which makes sense because i use await execute(..., ...) {
EdwardD
EdwardD10mo ago
Send all of the stuff you did previously in a pastebin Please
CoderZen
CoderZen10mo ago
i assume its occuring inside command Handler alr
EdwardD
EdwardD10mo ago
We will see
CoderZen
CoderZen10mo ago
Pastebin
discord.js v14 error - 1229 - Pastebin.com
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.
CoderZen
CoderZen10mo ago
everything is there - index.js - command handler - example command
EdwardD
EdwardD10mo ago
Thank you I'll take a read through Found the issue
CoderZen
CoderZen10mo ago
oh really?
EdwardD
EdwardD10mo ago
Line 5 on the pastebin, you are saying, if the command is a message in a channel like these right now, execute a command You are using slash commands right?
CoderZen
CoderZen10mo ago
yes so your trying to say that isChatInputCommands are used for prefixed commands?
EdwardD
EdwardD10mo ago
I'll write you a replacement interactionCreate.js
CoderZen
CoderZen10mo ago
that would be great
EdwardD
EdwardD10mo ago
Like the old !help
CoderZen
CoderZen10mo ago
yes i am unsure about that because previously, i tried it and it worked. i tried it as an interaction command and it didnt cause the error mentioned above
EdwardD
EdwardD10mo ago
This should work, if it doesn't we can work more on it Wait a sec Don't use that
EdwardD
EdwardD10mo ago
Pastebin
module.exports = { name: 'interactionCreate', async execute(i...
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.
CoderZen
CoderZen10mo ago
alr
EdwardD
EdwardD10mo ago
It might work, might not, if it doesn't we work on it
CoderZen
CoderZen10mo ago
EdwardD
EdwardD10mo ago
Is it an indentation issue?
CoderZen
CoderZen10mo ago
uh did u mean elseif {}?
EdwardD
EdwardD10mo ago
Both work Hold up a second
CoderZen
CoderZen10mo ago
CoderZen
CoderZen10mo ago
js is starting to make no sense
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZen10mo ago
yet i get another error
EdwardD
EdwardD10mo ago
Hold up I wrote that really badly Let me redo it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZen10mo ago
what are the difference? 🤔
EdwardD
EdwardD10mo ago
I like doing it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZen10mo ago
ahh i see i learned a lot of lang mixup its common
EdwardD
EdwardD10mo ago
This will work much better
EdwardD
EdwardD10mo ago
Pastebin
module.exports = { name: 'interactionCreate', async execute(i...
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.
CoderZen
CoderZen10mo ago
alr
EdwardD
EdwardD10mo ago
It isn't formatted properly because of pastebin but your ide should sort that out
CoderZen
CoderZen10mo ago
u added a extra } i removed it lets see
EdwardD
EdwardD10mo ago
Sorry, hard to code on pastebin
CoderZen
CoderZen10mo ago
TypeError: command.execute is not a function
at Object.execute (/workspace/official-realtrickz-community-bot/src/events/client/interactionCreate.js:12:31)
at Client.<anonymous> (/workspace/official-realtrickz-community-bot/src/functions/handlers/handleEvents.js:15:63)
at Client.emit (node:events:514:28)
at InteractionCreateAction.handle (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/workspace/official-realtrickz-community-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/workspace/official-realtrickz-community-bot/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/workspace/official-realtrickz-community-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
TypeError: command.execute is not a function
at Object.execute (/workspace/official-realtrickz-community-bot/src/events/client/interactionCreate.js:12:31)
at Client.<anonymous> (/workspace/official-realtrickz-community-bot/src/functions/handlers/handleEvents.js:15:63)
at Client.emit (node:events:514:28)
at InteractionCreateAction.handle (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/workspace/official-realtrickz-community-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/workspace/official-realtrickz-community-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/workspace/official-realtrickz-community-bot/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/workspace/official-realtrickz-community-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
EdwardD
EdwardD10mo ago
Alright we are getting somewhere now
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
EdwardD
EdwardD10mo ago
Did you get that message before?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
EdwardD
EdwardD10mo ago
They didn't tell us that the bot sent a message
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZen10mo ago
try {
await command.execute(interaction, client);
} catch (error) {
console.log(error);
await interaction.reply({
content: `Something went wrong while executing this command....`,
ephemeral: true
})
try {
await command.execute(interaction, client);
} catch (error) {
console.log(error);
await interaction.reply({
content: `Something went wrong while executing this command....`,
ephemeral: true
})
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZen10mo ago
wait
const { dir } = require("console");
const { ComponentType, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, SelectMenuBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("help")
.setDescription("View commands that has been implemented to this bot."),

async execute(interaction, client) {
const emojis = {
economy: "💰",
giveaways: "🎁",
moderation: "🦾",
tools: "⛏"
}

const directories = [
...new Set(interaction.client.commands.map((cmd) => cmd.folder)),
];

const formatString = (str) => `${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`;

const catagories = directories.map((dir) => {
const getCommands = interaction.client.commands.filter((cmd) => cmd.folder === dir).map((cmd) => {
return {
name: cmd.data.name,
description: cmd.data.description || "There is no description for this command.",
}
})

return {
directory: formatString(dir),
commands: getCommands,
}
})

const embed = new EmbedBuilder().setDescription("Please choose a catagory from the menu.")
const compontents = (state) => [
new ActionRowBuilder().addComponents(
new SelectMenuBuilder()
.setCustomId("help-menu")
.setPlaceholder("Please select a catagory.")
.setDisabled(state)
.addOptions(
catagories.map((cmd) => {
return {
label: cmd.directory,
value: cmd.directory.toLowerCase(),
description: `Commands from ${cmd.directory} catagory.`,
emoji: emojis[cmd.directory.toLowerCase() || null],
}
})
)
)
]

const initialMessage = await interaction.reply({
embeds: [embed],
compontents: compontents(false),
});

const filter = (interaction) => interaction.user.id === interaction.member.id;
const collector = interaction.channel.createMessageComponentCollector({
filter,
componentType: ComponentType.SelectMenuBuilder,
})

collector.on("collect", (interaction) => {
const [directories] = interaction.values;
const catagory = catagories.find(
(x) => x.directory.toLowerCase() === directory
);

const catagoryEmbed = new EmbedBuilder()
.setTitle(`${formatString(directory)} commands`)
.setDescription(`A list of all the commands catagorized under ${directory}`)
.addFields(
catagory.commands.map((cmd) => {
return {
name: `\`${cmd.name}\``,
value: cmd.description,
inline: true,
};
})
);

interaction.update({embeds: [catagoryEmbed]})
});

collector.on("end", () => {
initialMessage.edit({ compontents: compontents(true) });
})
},
};
const { dir } = require("console");
const { ComponentType, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, SelectMenuBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("help")
.setDescription("View commands that has been implemented to this bot."),

async execute(interaction, client) {
const emojis = {
economy: "💰",
giveaways: "🎁",
moderation: "🦾",
tools: "⛏"
}

const directories = [
...new Set(interaction.client.commands.map((cmd) => cmd.folder)),
];

const formatString = (str) => `${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`;

const catagories = directories.map((dir) => {
const getCommands = interaction.client.commands.filter((cmd) => cmd.folder === dir).map((cmd) => {
return {
name: cmd.data.name,
description: cmd.data.description || "There is no description for this command.",
}
})

return {
directory: formatString(dir),
commands: getCommands,
}
})

const embed = new EmbedBuilder().setDescription("Please choose a catagory from the menu.")
const compontents = (state) => [
new ActionRowBuilder().addComponents(
new SelectMenuBuilder()
.setCustomId("help-menu")
.setPlaceholder("Please select a catagory.")
.setDisabled(state)
.addOptions(
catagories.map((cmd) => {
return {
label: cmd.directory,
value: cmd.directory.toLowerCase(),
description: `Commands from ${cmd.directory} catagory.`,
emoji: emojis[cmd.directory.toLowerCase() || null],
}
})
)
)
]

const initialMessage = await interaction.reply({
embeds: [embed],
compontents: compontents(false),
});

const filter = (interaction) => interaction.user.id === interaction.member.id;
const collector = interaction.channel.createMessageComponentCollector({
filter,
componentType: ComponentType.SelectMenuBuilder,
})

collector.on("collect", (interaction) => {
const [directories] = interaction.values;
const catagory = catagories.find(
(x) => x.directory.toLowerCase() === directory
);

const catagoryEmbed = new EmbedBuilder()
.setTitle(`${formatString(directory)} commands`)
.setDescription(`A list of all the commands catagorized under ${directory}`)
.addFields(
catagory.commands.map((cmd) => {
return {
name: `\`${cmd.name}\``,
value: cmd.description,
inline: true,
};
})
);

interaction.update({embeds: [catagoryEmbed]})
});

collector.on("end", () => {
initialMessage.edit({ compontents: compontents(true) });
})
},
};
CoderZen
CoderZen10mo ago
every command has the same error
CoderZen
CoderZen10mo ago
hm?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZen10mo ago
it is saved im not sure what you mean by "you’re not using execute as the function in each command file"
async execute(...,...) => {
}
async execute(...,...) => {
}
?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZen10mo ago
alr
{
data: SlashCommandBuilder {
options: [],
name: 'help',
name_localizations: undefined,
description: 'View commands that has been implemented to this bot.',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined,
nsfw: undefined
},
execute: [AsyncFunction: execute]
}
{
data: SlashCommandBuilder {
options: [],
name: 'ping',
name_localizations: undefined,
description: 'Responds with my latency in milliseconds.',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined,
nsfw: undefined
},
execute: [AsyncFunction: execute]
}
{
data: SlashCommandBuilder {
options: [],
name: 'help',
name_localizations: undefined,
description: 'View commands that has been implemented to this bot.',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined,
nsfw: undefined
},
execute: [AsyncFunction: execute]
}
{
data: SlashCommandBuilder {
options: [],
name: 'ping',
name_localizations: undefined,
description: 'Responds with my latency in milliseconds.',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined,
nsfw: undefined
},
execute: [AsyncFunction: execute]
}
because it only has 2 commands?
CoderZen
CoderZen10mo ago
CoderZen
CoderZen10mo ago
{ '0': 'help.js', '1': 'ping.js', folder: 'tools' }
{ '0': 'help.js', '1': 'ping.js', folder: 'tools' }
CoderZen
CoderZen10mo ago
CoderZen
CoderZen10mo ago
this bothers me a lot
Not So Marv
Not So Marv10mo ago
I know this doesn't pertain to your current error but it will return an error later:
-componentType: ComponentType.SelectMenuBuilder,
+componentType: ComponentType.StringSelect,
-componentType: ComponentType.SelectMenuBuilder,
+componentType: ComponentType.StringSelect,
Also remove the first line const { dir } = require("console"); SelectMenuBuilder StringSelectMenuBuilder
CoderZen
CoderZen10mo ago
done i logged { '0': 'help.js', '1': 'ping.js', folder: 'tools' } idk how is that gonna help guys? so how do i fix it index? i showed cmd handler
CoderZen
CoderZen10mo ago
this is all i have currently
CoderZen
CoderZen10mo ago
// env
require("dotenv").config();

// work starts here
const { token } = process.env;
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const fs = require("fs");

const client = new Client({ intents: GatewayIntentBits.Guilds });
client.commands = new Collection();
client.commandArray = [];

const functionFolders = fs.readdirSync(`./src/functions`);
for (const folder of functionFolders) {
const functionFiles = fs
.readdirSync(`./src/functions/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of functionFiles)
require(`./src/functions/${folder}/${file}`)(client);
}

client.handleEvents();
client.handleCommands()
client.login(token)
// env
require("dotenv").config();

// work starts here
const { token } = process.env;
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const fs = require("fs");

const client = new Client({ intents: GatewayIntentBits.Guilds });
client.commands = new Collection();
client.commandArray = [];

const functionFolders = fs.readdirSync(`./src/functions`);
for (const folder of functionFolders) {
const functionFiles = fs
.readdirSync(`./src/functions/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of functionFiles)
require(`./src/functions/${folder}/${file}`)(client);
}

client.handleEvents();
client.handleCommands()
client.login(token)
index cant find it hm lemme show handleCommands
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9')
const fs = require("fs");

module.exports = (client) => {
client.handleCommands = async () => {
const commandFolders = fs.readdirSync(`./src/commands`);
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./src/commands/${folder}`)
.filter((file) => file.endsWith(`.js`));

const { commands, commandArray } = client;
for (const file of commandFiles) {
const command = require(`../../commands/${folder}/${file}`)
const properties = {folder, ...commandFiles};
// console.log(command);
commands.set(command.data.name, properties) // command
commandArray.push(command.data.toJSON());
// console.log(`Command: ${command.data.name} has been passed through the handler`);
}
}

const clientId = '1139096180312256612';
const guildId = '1139827130973302805';
const rest = new REST({ version: '9' }).setToken(process.env.token);
try {
console.log("Started refreshing application (/) commands.");

await rest.put(Routes.applicationCommands(clientId, guildId), {
body: client.commandArray,
});

console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.log(error);
}
};
};
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9')
const fs = require("fs");

module.exports = (client) => {
client.handleCommands = async () => {
const commandFolders = fs.readdirSync(`./src/commands`);
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./src/commands/${folder}`)
.filter((file) => file.endsWith(`.js`));

const { commands, commandArray } = client;
for (const file of commandFiles) {
const command = require(`../../commands/${folder}/${file}`)
const properties = {folder, ...commandFiles};
// console.log(command);
commands.set(command.data.name, properties) // command
commandArray.push(command.data.toJSON());
// console.log(`Command: ${command.data.name} has been passed through the handler`);
}
}

const clientId = '1139096180312256612';
const guildId = '1139827130973302805';
const rest = new REST({ version: '9' }).setToken(process.env.token);
try {
console.log("Started refreshing application (/) commands.");

await rest.put(Routes.applicationCommands(clientId, guildId), {
body: client.commandArray,
});

console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.log(error);
}
};
};
its for my help cmd properties is essential for handleCommands
/workspace/official-realtrickz-community-bot/src/functions/handlers/handleCommands.js:18
commands.set(command.data.name, properties) // command
^

ReferenceError: properties is not defined
at client.handleCommands (/workspace/official-realtrickz-community-bot/src/functions/handlers/handleCommands.js:18:45)
at Object.<anonymous> (/workspace/official-realtrickz-community-bot/index.js:23:8)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
/workspace/official-realtrickz-community-bot/src/functions/handlers/handleCommands.js:18
commands.set(command.data.name, properties) // command
^

ReferenceError: properties is not defined
at client.handleCommands (/workspace/official-realtrickz-community-bot/src/functions/handlers/handleCommands.js:18:45)
at Object.<anonymous> (/workspace/official-realtrickz-community-bot/index.js:23:8)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
commands.set(command.data.name, properties) but it breaks it what did follow but i was able to understand other than a few parts property is a constant with value {folder, ...commandFiles}; folder = commandFolders for example folders inside the 'commands' directory such as 'tools' commandFiles are those who ends with .js assuming its fetching those huh i dont know what to do anymore so im gonna write the code from scratch is that a good idea? ok handleCommands?
-const commandFiles = fs.readdirSync(`./src/commands/${folder}`).filter((file) => file.endsWith(`.js`));

+const command = fs.readdirSync(`./src/commands/${folder}`).filter((file) => file.endsWith(`.js`));
-const commandFiles = fs.readdirSync(`./src/commands/${folder}`).filter((file) => file.endsWith(`.js`));

+const command = fs.readdirSync(`./src/commands/${folder}`).filter((file) => file.endsWith(`.js`));
this? awesome, that works im so greatful
CoderZen
CoderZen10mo ago
but doesnt seem to implement the menu? thinkLul