Hello sorry im new to this but did i do this right

const { Client, Intents } = require('discord.js');
require('dotenv').config();

const client = new Client({
intents: [
Intents.FLAGS.GUILDS, // Allows the bot to interact with guilds (servers)
Intents.FLAGS.GUILD_MESSAGES
]
});

client.commands = new Map();

const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}

client.once('ready', () => {
console.log('Bot is ready!');

client.user.setPresence({
activities: [{ name: 'd', type: 'PLAYING' }],
status: 'online',
});


const guildId = '1254264050658054204';

client.guilds.cache.get(guildId)?.commands.set(Array.from(client.commands.values())).then(() => {
console.log('Slash commands registered!');
}).catch(console.error);
});

client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;

const { commandName } = interaction;

if (!client.commands.has(commandName)) return;

try {
await client.commands.get(commandName).execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error executing this command.', ephemeral: true });
}
});

client.login(process.env.DISCORD_TOKEN);
const { Client, Intents } = require('discord.js');
require('dotenv').config();

const client = new Client({
intents: [
Intents.FLAGS.GUILDS, // Allows the bot to interact with guilds (servers)
Intents.FLAGS.GUILD_MESSAGES
]
});

client.commands = new Map();

const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}

client.once('ready', () => {
console.log('Bot is ready!');

client.user.setPresence({
activities: [{ name: 'd', type: 'PLAYING' }],
status: 'online',
});


const guildId = '1254264050658054204';

client.guilds.cache.get(guildId)?.commands.set(Array.from(client.commands.values())).then(() => {
console.log('Slash commands registered!');
}).catch(console.error);
});

client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;

const { commandName } = interaction;

if (!client.commands.has(commandName)) return;

try {
await client.commands.get(commandName).execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error executing this command.', ephemeral: true });
}
});

client.login(process.env.DISCORD_TOKEN);
72 Replies
d.js toolkit
d.js toolkit3mo 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!
monbrey
monbrey3mo ago
Some of this looks like v13 code, not v14
d.js docs
d.js docs3mo ago
:guide: Additional Information: Updating from v13 to v14 read more
Jereme
Jereme3mo ago
@ʎǝɹquoɯ did i fi it
const { Client, Intents, Collection } = require('discord.js');
const fs = require('fs');
require('dotenv').config(); // Load environment variables from .env file

const client = new Client({
intents: [
Intents.FLAGS.GUILDS, // Allows the bot to interact with guilds (servers)
Intents.FLAGS.GUILD_MESSAGES // Allows the bot to receive messages in guilds
],
});

client.commands = new Collection(); // Use Collection instead of Map for Discord.js v14

// Dynamically load commands from the commands directory
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}

client.once('ready', () => {
console.log('Bot is ready!');

client.user.setPresence({
activities: [{ name: 'with Discord.js v14', type: 'PLAYING' }],
status: 'online',
});

const guildId = 'YOUR_SERVER_ID'; // Replace with your Discord server ID

client.guilds.cache.get(guildId)?.commands.set(Array.from(client.commands.values())).then(() => {
console.log('Slash commands registered!');
}).catch(console.error);
});

client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;

const { commandName } = interaction;

if (!client.commands.has(commandName)) return;

try {
await client.commands.get(commandName).execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error executing this command.', ephemeral: true });
}
});

client.login(process.env.DISCORD_TOKEN);
const { Client, Intents, Collection } = require('discord.js');
const fs = require('fs');
require('dotenv').config(); // Load environment variables from .env file

const client = new Client({
intents: [
Intents.FLAGS.GUILDS, // Allows the bot to interact with guilds (servers)
Intents.FLAGS.GUILD_MESSAGES // Allows the bot to receive messages in guilds
],
});

client.commands = new Collection(); // Use Collection instead of Map for Discord.js v14

// Dynamically load commands from the commands directory
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}

client.once('ready', () => {
console.log('Bot is ready!');

client.user.setPresence({
activities: [{ name: 'with Discord.js v14', type: 'PLAYING' }],
status: 'online',
});

const guildId = 'YOUR_SERVER_ID'; // Replace with your Discord server ID

client.guilds.cache.get(guildId)?.commands.set(Array.from(client.commands.values())).then(() => {
console.log('Slash commands registered!');
}).catch(console.error);
});

client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;

const { commandName } = interaction;

if (!client.commands.has(commandName)) return;

try {
await client.commands.get(commandName).execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error executing this command.', ephemeral: true });
}
});

client.login(process.env.DISCORD_TOKEN);
monbrey
monbrey3mo ago
The Intents have changed no, nothing here is fixed Are you using ChatGPT or something?
Jereme
Jereme3mo ago
no i put // Replace with your Discord server ID so i know
monbrey
monbrey3mo ago
If you dont mind me asking, where are you getting the outdated code from?
Jereme
Jereme3mo ago
bc im still learnign and it is notes youtube and myself
monbrey
monbrey3mo ago
I recommend following our guide for the most up to date code and references https://discordjs.guide/#before-you-begin
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Jereme
Jereme3mo ago
i try and i might give up bc im trying to make all this with no help
**Main BOT**
Welcome
Tickets | 4 - 5
Server Status Monitoring
Embeds
Polls
Reaction Roles
Chat AI
Social Notify
Invite Tracker
Giveaway
Counting
Leveling
Verification
Message Staff app
Sneak Peak - Announcements - Updates
Games
Music
Suggestions

**Manager Bot**
Security
Logging
Auto moderation
moderation
Staff Add - Remove - show all
**Main BOT**
Welcome
Tickets | 4 - 5
Server Status Monitoring
Embeds
Polls
Reaction Roles
Chat AI
Social Notify
Invite Tracker
Giveaway
Counting
Leveling
Verification
Message Staff app
Sneak Peak - Announcements - Updates
Games
Music
Suggestions

**Manager Bot**
Security
Logging
Auto moderation
moderation
Staff Add - Remove - show all
so
monbrey
monbrey3mo ago
That is quite a lot and our guide definitely doesnt cover all of that
Jereme
Jereme3mo ago
ik
youiss
youiss3mo ago
:monkaStop: I would quit coding discord bot and do something more useful just saying
Jereme
Jereme3mo ago
it is for my server
youiss
youiss3mo ago
if you are a beginner those might be little too hard for you
Want results from more Discord servers?
Add your server