client.on Error
Hello. The first Code block are my Code and the Second is the Error.
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } = require('discord.js');
const { Client } = require('discord.js');
const client = require('../../../index.js').client;
// Replace 'YOUR_CHANNEL_ID_HERE' with the actual channel ID
const CHANNEL_ID = '1222955254174453945';
const exampleEmbed = new EmbedBuilder()
.setTitle('Stempeluhr')
.setThumbnail('https://cdn.pixabay.com/photo/2016/08/19/20/37/time-1606153_1280.png')
.setDescription(`Sie haben sich erfolgreich eingestempelt: <t:${Date.now()}:R>`);
client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
if (interaction.message.id !== interaction.message.id) return;
if (interaction.customId === 'einstempeln') {
const channel = client.channels.cache.get(CHANNEL_ID);
if (channel) {
await channel.send({ embeds: [exampleEmbed] });
interaction.message.edit({ components: [] });
interaction.reply({ content: 'Sie haben sich erfolgreich eingestempelt!', ephemeral: true });
} else {
// Handle the case where the channel is not found
console.log(`Channel with ID ${CHANNEL_ID} not found`);
}
}
});
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } = require('discord.js');
const { Client } = require('discord.js');
const client = require('../../../index.js').client;
// Replace 'YOUR_CHANNEL_ID_HERE' with the actual channel ID
const CHANNEL_ID = '1222955254174453945';
const exampleEmbed = new EmbedBuilder()
.setTitle('Stempeluhr')
.setThumbnail('https://cdn.pixabay.com/photo/2016/08/19/20/37/time-1606153_1280.png')
.setDescription(`Sie haben sich erfolgreich eingestempelt: <t:${Date.now()}:R>`);
client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
if (interaction.message.id !== interaction.message.id) return;
if (interaction.customId === 'einstempeln') {
const channel = client.channels.cache.get(CHANNEL_ID);
if (channel) {
await channel.send({ embeds: [exampleEmbed] });
interaction.message.edit({ components: [] });
interaction.reply({ content: 'Sie haben sich erfolgreich eingestempelt!', ephemeral: true });
} else {
// Handle the case where the channel is not found
console.log(`Channel with ID ${CHANNEL_ID} not found`);
}
}
});
4 Replies
- 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!Error:
node:internal/modules/cjs/loader:1152
throw err;
^
Error: Cannot find module '../../../index.js'
Require stack:
- C:\Users\User\Desktop\BenniTechniker\commands\utility\stempeluhr.js
- C:\Users\User\Desktop\BenniTechniker\deploy-commands.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1149:15)
at Module._load (node:internal/modules/cjs/loader:990:27)
at Module.require (node:internal/modules/cjs/loader:1237:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (C:\Users\User\Desktop\BenniTechniker\commands\utility\stempeluhr.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Module.require (node:internal/modules/cjs/loader:1237:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\User\\Desktop\\BenniTechniker\\commands\\utility\\stempeluhr.js',
'C:\\Users\\User\\Desktop\\BenniTechniker\\deploy-commands.js'
]
}
node:internal/modules/cjs/loader:1152
throw err;
^
Error: Cannot find module '../../../index.js'
Require stack:
- C:\Users\User\Desktop\BenniTechniker\commands\utility\stempeluhr.js
- C:\Users\User\Desktop\BenniTechniker\deploy-commands.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1149:15)
at Module._load (node:internal/modules/cjs/loader:990:27)
at Module.require (node:internal/modules/cjs/loader:1237:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (C:\Users\User\Desktop\BenniTechniker\commands\utility\stempeluhr.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Module.require (node:internal/modules/cjs/loader:1237:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\User\\Desktop\\BenniTechniker\\commands\\utility\\stempeluhr.js',
'C:\\Users\\User\\Desktop\\BenniTechniker\\deploy-commands.js'
]
}
This code is a mess
Your path to index is wrong, but you shouldnt be importing client from there anyway