Missing required "data" or "execute" property

Hello.ts
import { SlashCommandBuilder, type CommandInteraction } from "discord.js";

export default {
data: new SlashCommandBuilder()
.setName("hello")
.setDescription("Says Hello"),
async execute(interaction: CommandInteraction) {
// Get the user who triggered the interaction
const user = interaction.user;
// Construct the reply message with the user's mention
const replyMessage = `Hello ${user}!`;
// Reply to the interaction
await interaction.reply(replyMessage);
},
}
import { SlashCommandBuilder, type CommandInteraction } from "discord.js";

export default {
data: new SlashCommandBuilder()
.setName("hello")
.setDescription("Says Hello"),
async execute(interaction: CommandInteraction) {
// Get the user who triggered the interaction
const user = interaction.user;
// Construct the reply message with the user's mention
const replyMessage = `Hello ${user}!`;
// Reply to the interaction
await interaction.reply(replyMessage);
},
}
Command Handler:
export function LoadCommands({ mainFolder, token, clientID, client, guildID, }: LoadCommandsParams) {
const commands: JSON[] = [];
const commandFolders = fs.readdirSync(mainFolder);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(mainFolder, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

const rest = new REST().setToken(token);

async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientID, guildID),
{ body: commands },
);

console.log(`Successfully reloaded ${(data as string[]).length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
}
}
export function LoadCommands({ mainFolder, token, clientID, client, guildID, }: LoadCommandsParams) {
const commands: JSON[] = [];
const commandFolders = fs.readdirSync(mainFolder);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(mainFolder, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

const rest = new REST().setToken(token);

async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientID, guildID),
{ body: commands },
);

console.log(`Successfully reloaded ${(data as string[]).length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
}
}
Error: [WARNING] The command at /Users/eveeifyeve/projects/Social-Bots/bots/core/src/commands/general/hello.ts is missing a required "data" or "execute" property.
2 Replies
d.js toolkit
d.js toolkit9mo 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 OP
eveeifyeve
eveeifyeveOP9mo ago
Fixed issue it was .deafult that had to been added.
Want results from more Discord servers?
Add your server