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 toolkit16mo 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/luna16mo ago
well show your command
EdwardD
EdwardD16mo ago
I got this, was just working with this guy in v14 help
CoderZen
CoderZenOP16mo ago
it happens everytime i run a command which makes sense because i use await execute(..., ...) {
EdwardD
EdwardD16mo ago
Send all of the stuff you did previously in a pastebin Please
CoderZen
CoderZenOP16mo ago
i assume its occuring inside command Handler alr
EdwardD
EdwardD16mo ago
We will see
CoderZen
CoderZenOP16mo 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
CoderZenOP16mo ago
everything is there - index.js - command handler - example command
EdwardD
EdwardD16mo ago
Thank you I'll take a read through Found the issue
CoderZen
CoderZenOP16mo ago
oh really?
EdwardD
EdwardD16mo 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
CoderZenOP16mo ago
yes so your trying to say that isChatInputCommands are used for prefixed commands?
EdwardD
EdwardD16mo ago
I'll write you a replacement interactionCreate.js
CoderZen
CoderZenOP16mo ago
that would be great
EdwardD
EdwardD16mo ago
Like the old !help
CoderZen
CoderZenOP16mo 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
EdwardD16mo ago
This should work, if it doesn't we can work more on it Wait a sec Don't use that
EdwardD
EdwardD16mo 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
CoderZenOP16mo ago
alr
EdwardD
EdwardD16mo ago
It might work, might not, if it doesn't we work on it
CoderZen
CoderZenOP16mo ago
EdwardD
EdwardD16mo ago
Is it an indentation issue?
CoderZen
CoderZenOP16mo ago
uh did u mean elseif {}?
EdwardD
EdwardD16mo ago
Both work Hold up a second
CoderZen
CoderZenOP16mo ago
CoderZen
CoderZenOP16mo ago
js is starting to make no sense
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZenOP16mo ago
yet i get another error
EdwardD
EdwardD16mo ago
Hold up I wrote that really badly Let me redo it
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZenOP16mo ago
what are the difference? 🤔
EdwardD
EdwardD16mo ago
I like doing it
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZenOP16mo ago
ahh i see i learned a lot of lang mixup its common
EdwardD
EdwardD16mo ago
This will work much better
EdwardD
EdwardD16mo 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
CoderZenOP16mo ago
alr
EdwardD
EdwardD16mo ago
It isn't formatted properly because of pastebin but your ide should sort that out
CoderZen
CoderZenOP16mo ago
u added a extra } i removed it lets see
EdwardD
EdwardD16mo ago
Sorry, hard to code on pastebin
CoderZen
CoderZenOP16mo 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
EdwardD16mo ago
Alright we are getting somewhere now
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
EdwardD
EdwardD16mo ago
Did you get that message before?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
EdwardD
EdwardD16mo ago
They didn't tell us that the bot sent a message
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZenOP16mo 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 User16mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZenOP16mo 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
CoderZenOP16mo ago
every command has the same error
CoderZen
CoderZenOP16mo ago
hm?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZenOP16mo 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 User16mo ago
Message Not Public
Sign In & Join Server To View
CoderZen
CoderZenOP16mo 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
CoderZenOP16mo ago
CoderZen
CoderZenOP16mo ago
{ '0': 'help.js', '1': 'ping.js', folder: 'tools' }
{ '0': 'help.js', '1': 'ping.js', folder: 'tools' }
CoderZen
CoderZenOP16mo ago
CoderZen
CoderZenOP16mo ago
this bothers me a lot
Not So Marv
Not So Marv16mo 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
CoderZenOP16mo 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
CoderZenOP16mo ago
this is all i have currently
CoderZen
CoderZenOP16mo 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
CoderZenOP16mo ago
but doesnt seem to implement the menu? thinkLul
Want results from more Discord servers?
Add your server