I need help with my Discord Bot

Can anyone help me with my bot? The command is not executed and no error appears in the console.
15 Replies
d.js toolkit
d.js toolkit14mo 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
treble/luna
treble/luna14mo ago
i told you to learn the basics of js first, not to ignore my answer and create a post
Jonas
JonasOP14mo ago
index:
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();


client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);

client.user.setPresence({ activities: [{ name: 'Minecraft' }], status: 'idle' });
});

client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}

client.login(token);
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();


client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);

client.user.setPresence({ activities: [{ name: 'Minecraft' }], status: 'idle' });
});

client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}

client.login(token);
command (user.js)
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
};
treble/luna
treble/luna14mo ago
please just learn js
Jonas
JonasOP14mo ago
Help me and I promise you that I can learn Discordjs as soon as possible
treble/luna
treble/luna14mo ago
No you will just run into more issues
Jonas
JonasOP14mo ago
Help me
duck
duck14mo ago
it will be very hard to help you if you don't know what a function is it will be much easier to learn how to use discord.js if you know the basics of javascript
Jonas
JonasOP14mo ago
I know what a function is
duck
duck14mo ago
so then could you elaborate on what you're confused about here? https://discord.com/channels/222078108977594368/824411059443204127/1171922079025737808
Jonas
JonasOP14mo ago
A function is a specific action that performs I just didn't know what was meant by function. It is difficult to write and understand German without a translator. I have a bit of an idea but I'm really desperate because I used to code with other development languages Im sorry..
duck
duck14mo ago
you don't need to continue the conversation in multiple places that being said, this still doesn't explain what exactly you're confused about you have a function that you export you were asked to show the code where you import and call this function
Jonas
JonasOP14mo ago
And that's exactly it. I don't know where to export the function. I think you mean deploy-commands.js
treble/luna
treble/luna14mo ago
you need to import it in your event handler or set it in your client.commands the guide covers this
Jonas
JonasOP14mo ago
Okay
Want results from more Discord servers?
Add your server