TypeError: Cannot read properties of undefined (reading 'data')
at Object.execute (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\events\slashCreate.js:27:30)
at Client.<anonymous> (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\bot.js:60:35)
at Client.emit (node:events:526:35)
at InteractionCreateAction.handle (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:397:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
/**
* @file Slash Command Interaction Handler
* @author Naman Vrati
* @since 3.0.0
* @version 3.3.0
*/
const {Collection} = require("discord.js");
module.exports = {
name: "interactionCreate",
/**
* @description Executes when an interaction is created and handle it.
* @author Naman Vrati
* @param {import('discord.js').CommandInteraction & { client: import('../typings').Client }} interaction The interaction which was created
*/
async execute(interaction) {
// Deconstructed client from interaction object.
const { client } = interaction;
// Checks if the interaction is a command (to prevent weird bugs)
const { cooldowns } = interaction.client;
const command = client.slashCommands.get(interaction.commandName);
if (!cooldowns.has(command.data.name)) {
cooldowns.set(command.data.name, new Collection());
}
const now = Date.now();
const timestamps = cooldowns.get(command.data.name);
const defaultCooldownDuration = 3;
const cooldownAmount = (command.cooldown ?? defaultCooldownDuration) * 1_000;
if (timestamps.has(interaction.user.id)) {
const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
if (now < expirationTime) {
const expiredTimestamp = Math.round(expirationTime / 1_000);
return interaction.reply({ content: `Please wait, you are on a cooldown for \`${command.data.name}\`. You can use it again <t:${expiredTimestamp}:R>.`, ephemeral: true });
}
}
timestamps.set(interaction.user.id, now);
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount);
if (!interaction.isChatInputCommand()) return;
// If the interaction is not a command in cache.
if (!command) return;
// A try to executes the interaction.
try {
await command.execute(interaction);
} catch (err) {
console.error(err);
await interaction.reply({
content: "There was an issue while executing that command!",
ephemeral: true,
});
}
},
};
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(
event.name,
async (...args) => await event.execute(...args, client)
);
}
}