eveeifyeve
DIAdiscord.js - Imagine an app
•Created by eveeifyeve on 11/16/2024 in #djs-questions
TS Bot Handlers not running with correct envs
can anyone figure out why the handlers in this bot is not working? I have provided correct envs.
https://github.com/TeaClientMC/Discord-Bot/
44 replies
DIAdiscord.js - Imagine an app
•Created by eveeifyeve on 4/13/2024 in #djs-questions
Missing required "data" or "execute" property
Hello.ts
Command Handler:
Error:
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);
},
}
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);
}
}
}
[WARNING] The command at /Users/eveeifyeve/projects/Social-Bots/bots/core/src/commands/general/hello.ts is missing a required "data" or "execute" property.
3 replies