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 toolkit5mo 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
monbrey5mo ago
Some of this looks like v13 code, not v14
d.js docs
d.js docs5mo ago
:guide: Additional Information: Updating from v13 to v14 read more
Jereme
JeremeOP5mo 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
monbrey5mo ago
The Intents have changed no, nothing here is fixed Are you using ChatGPT or something?
Jereme
JeremeOP5mo ago
no i put // Replace with your Discord server ID so i know
monbrey
monbrey5mo ago
If you dont mind me asking, where are you getting the outdated code from?
Jereme
JeremeOP5mo ago
bc im still learnign and it is notes youtube and myself
monbrey
monbrey5mo 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
JeremeOP5mo 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
monbrey5mo ago
That is quite a lot and our guide definitely doesnt cover all of that
Jereme
JeremeOP5mo ago
ik
youiss
youiss5mo ago
:monkaStop: I would quit coding discord bot and do something more useful just saying
Jereme
JeremeOP5mo ago
it is for my server
youiss
youiss5mo ago
if you are a beginner those might be little too hard for you
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
youiss
youiss5mo ago
Im not discouraging him lol
monbrey
monbrey5mo ago
You literally told him to quit
youiss
youiss5mo ago
shared my opinion
monbrey
monbrey5mo ago
Please leave this thread if you have no intention of helping people use discord.js
youiss
youiss5mo ago
👍🏻
monbrey
monbrey5mo ago
This is not a place to share your opinion Start with the basics and tackle the easy ones, build on those skills into more complicated items
Jereme
JeremeOP5mo ago
some one said py is better tf is the new intents
Kevinnnn
Kevinnnn5mo ago
Sure, the video is fine, it shows you how to start the basics for your bot
Jereme
JeremeOP5mo ago
i got all that i just need the intents
Kevinnnn
Kevinnnn5mo ago
The intents didn't change between v13 and v14, they just changed what name they are under
d.js docs
d.js docs5mo ago
:guide: Popular Topics: Gateway Intents read more
Jereme
JeremeOP5mo ago
@Jô 🌈🦄 you apere out of air ty jo do yall have a thing on this client.once('ready', () => { console.log('Bot is ready!'); client.user.setPresence({ activities: [{ name: 'd', type: 'PLAYING' }], status: 'online', });
d.js docs
d.js docs5mo ago
:guide: Creating Your Bot: Event handling read more
Jereme
JeremeOP5mo ago
ok so i made the index to were it will auto make my command
Kevinnnn
Kevinnnn5mo ago
is this something you made or some package/chatgpt thing? djs doesn't have anything that automatically makes commands
Jereme
JeremeOP5mo ago
no like it regesters and it is from my old bot that my frinde fix like 3 things
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Kevinnnn
Kevinnnn5mo ago
there is something similar in the guide, you can try to use the one you have or make a new one from the guide
d.js docs
d.js docs5mo ago
:guide: Creating Your Bot: Command handling read more
Jereme
JeremeOP5mo ago
oh i got it - i got the
module.exports = {
name: 'ping',
description: 'Returns bot\'s latency and other info',
async execute(interaction) {
const { client } = interaction;

// Calculate latency between sending a message and editing it
const startTime = Date.now();
const reply = await interaction.reply({ content: 'Pinging...', ephemeral: true });
const endTime = Date.now();
const latency = endTime - startTime;

// Edit the reply to show bot's ping and API latency
reply.edit({
content: `Bot latency: ${latency}ms\nAPI latency: ${client.ws.ping}ms`,
ephemeral: true
});
},
};
module.exports = {
name: 'ping',
description: 'Returns bot\'s latency and other info',
async execute(interaction) {
const { client } = interaction;

// Calculate latency between sending a message and editing it
const startTime = Date.now();
const reply = await interaction.reply({ content: 'Pinging...', ephemeral: true });
const endTime = Date.now();
const latency = endTime - startTime;

// Edit the reply to show bot's ping and API latency
reply.edit({
content: `Bot latency: ${latency}ms\nAPI latency: ${client.ws.ping}ms`,
ephemeral: true
});
},
};
now i got to make a embed maker witch im go do
d.js docs
d.js docs5mo ago
:guide: Popular Topics: Embeds - Using the embed constructor read more
Jereme
JeremeOP5mo ago
i found it yes no
const { MessageEmbed } = require('discord.js');

module.exports = {
name: 'embedcreate',
description: 'Creates a customizable embed message',
options: [
{
name: 'title',
type: 'STRING',
description: 'Title of the embed',
required: true,
},
{
name: 'description',
type: 'STRING',
description: 'Description of the embed',
required: true,
},
{
name: 'image',
type: 'STRING',
description: 'URL of the image for the embed',
required: false,
},
],
execute(interaction) {
const { options } = interaction;

const title = options.getString('title');
const description = options.getString('description');
const imageUrl = options.getString('image');

const embed = new MessageEmbed()
.setColor('#0096ff')
.setTitle(title)
.setDescription(description)
.setTimestamp();

if (imageUrl) {
embed.setImage(imageUrl);
}

embed.setFooter('Powerd By SkyFade');

interaction.reply({ embeds: [embed], ephemeral: true });
},
};
const { MessageEmbed } = require('discord.js');

module.exports = {
name: 'embedcreate',
description: 'Creates a customizable embed message',
options: [
{
name: 'title',
type: 'STRING',
description: 'Title of the embed',
required: true,
},
{
name: 'description',
type: 'STRING',
description: 'Description of the embed',
required: true,
},
{
name: 'image',
type: 'STRING',
description: 'URL of the image for the embed',
required: false,
},
],
execute(interaction) {
const { options } = interaction;

const title = options.getString('title');
const description = options.getString('description');
const imageUrl = options.getString('image');

const embed = new MessageEmbed()
.setColor('#0096ff')
.setTitle(title)
.setDescription(description)
.setTimestamp();

if (imageUrl) {
embed.setImage(imageUrl);
}

embed.setFooter('Powerd By SkyFade');

interaction.reply({ embeds: [embed], ephemeral: true });
},
};
i think i did good just got to waait for my bot to chatch
Kevinnnn
Kevinnnn5mo ago
option types aren't uppercase strings anymore, they are either enums or numbers
Jereme
JeremeOP5mo ago
what wait do i have to export it
Kevinnnn
Kevinnnn5mo ago
yes, it is a type you have to import otherwise you can use the corresponding numbers
Jereme
JeremeOP5mo ago
no fo it to work do i have to export it
d.js docs
d.js docs5mo ago
:guide: Slash Commands: Advanced command creation read more
TÆMBØ
TÆMBØ5mo ago
Please be sure that the code you're using is for the correct version. You tagged this post for v14, however MessageEmbed is found in v13
Kevinnnn
Kevinnnn5mo ago
what guide are you using ^^ you're on discord.js v14 but the code you've been providing has been v13
Jereme
JeremeOP5mo ago
oh dam im on the one you give im using some stuff from my old bot from v13
Jereme
JeremeOP5mo ago
i can find it as of what it is to do what im doing
Kevinnnn
Kevinnnn5mo ago
could you rephrase that maybe? I have no idea what youre asking here
Jereme
JeremeOP5mo ago
ii cant find how the embed thing im making is made
Kevinnnn
Kevinnnn5mo ago
what are you looking for that is different from what the guide provides?
No description
Jereme
JeremeOP5mo ago
this
const { EmbedBuilder } = require('discord.js');

module.exports = {
name: 'embedcreate',
description: 'Creates a customizable embed message',
options: [
{
name: 'title',
type: 'STRING',
description: 'Title of the embed',
required: true,
},
{
name: 'description',
type: 'STRING',
description: 'Description of the embed',
required: true,
},
{
name: 'image',
type: 'STRING',
description: 'URL of the image for the embed',
required: false,
},
],
execute(interaction) {
const { options } = interaction;

const title = options.getString('title');
const description = options.getString('description');
const imageUrl = options.getString('image');

const embed = new EmbedBuilder()
.setColor('#0096ff')
.setTitle(title)
.setDescription(description)
.setTimestamp();

if (imageUrl) {
embed.setImage(imageUrl);
}

embed.setFooter('Powerd By SkyFade');

interaction.reply({ embeds: [embed], ephemeral: true });
},
};
const { EmbedBuilder } = require('discord.js');

module.exports = {
name: 'embedcreate',
description: 'Creates a customizable embed message',
options: [
{
name: 'title',
type: 'STRING',
description: 'Title of the embed',
required: true,
},
{
name: 'description',
type: 'STRING',
description: 'Description of the embed',
required: true,
},
{
name: 'image',
type: 'STRING',
description: 'URL of the image for the embed',
required: false,
},
],
execute(interaction) {
const { options } = interaction;

const title = options.getString('title');
const description = options.getString('description');
const imageUrl = options.getString('image');

const embed = new EmbedBuilder()
.setColor('#0096ff')
.setTitle(title)
.setDescription(description)
.setTimestamp();

if (imageUrl) {
embed.setImage(imageUrl);
}

embed.setFooter('Powerd By SkyFade');

interaction.reply({ embeds: [embed], ephemeral: true });
},
};
Kevinnnn
Kevinnnn5mo ago
anddddd what does it not have?
Jereme
JeremeOP5mo ago
sorry but im new to v14 and stuff
Kevinnnn
Kevinnnn5mo ago
I'm confused on what you say isn't in the guide that is in your code
Jereme
JeremeOP5mo ago
string
Kevinnnn
Kevinnnn5mo ago
For options or the embed?
Jereme
JeremeOP5mo ago
both
Kevinnnn
Kevinnnn5mo ago
we'll start with options
d.js docs
d.js docs5mo ago
:guide: Slash Commands: Advanced command creation read more
Jereme
JeremeOP5mo ago
wait did i do it right or bc im dumb
Kevinnnn
Kevinnnn5mo ago
how are you parsing your slash commands data when updating your slash commands?
Jereme
JeremeOP5mo ago
huh
Kevinnnn
Kevinnnn5mo ago
when you upload slash commands to discord, what code are you using to do that
Jereme
JeremeOP5mo ago
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.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.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.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 });
}
});
Kevinnnn
Kevinnnn5mo ago
and where is your deploy-commands.js?
Jereme
JeremeOP5mo ago
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
require('dotenv').config();

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}

const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID), // Replace CLIENT_ID with your bot's client ID
{ body: commands },
);

console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
require('dotenv').config();

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}

const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID), // Replace CLIENT_ID with your bot's client ID
{ body: commands },
);

console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
oh and
0.options[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).
0.options[1][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).
0.options[2][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).
at handleErrors (C:\Users\dolph\Downloads\SkyFade\node_modules\@discordjs\rest\dist\index.js:730:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\dolph\Downloads\SkyFade\node_modules\@discordjs\rest\dist\index.js:1133:23)
at async SequentialHandler.queueRequest (C:\Users\dolph\Downloads\SkyFade\node_modules\@discordjs\rest\dist\index.js:963:14)
at async _REST.request (C:\Users\dolph\Downloads\SkyFade\node_modules\@discordjs\rest\dist\index.js:1278:22)
at async GuildApplicationCommandManager.set (C:\Users\dolph\Downloads\SkyFade\node_modules\discord.js\src\managers\ApplicationCommandManager.js:171:18) {
requestBody: { files: undefined, json: [ [Object], [Object] ] },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { '0': [Object] }
},
code: 50035,
status: 400,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1254637442628321361/guilds/1254264050658054204/commands'
}
0.options[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).
0.options[1][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).
0.options[2][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).
at handleErrors (C:\Users\dolph\Downloads\SkyFade\node_modules\@discordjs\rest\dist\index.js:730:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\dolph\Downloads\SkyFade\node_modules\@discordjs\rest\dist\index.js:1133:23)
at async SequentialHandler.queueRequest (C:\Users\dolph\Downloads\SkyFade\node_modules\@discordjs\rest\dist\index.js:963:14)
at async _REST.request (C:\Users\dolph\Downloads\SkyFade\node_modules\@discordjs\rest\dist\index.js:1278:22)
at async GuildApplicationCommandManager.set (C:\Users\dolph\Downloads\SkyFade\node_modules\discord.js\src\managers\ApplicationCommandManager.js:171:18) {
requestBody: { files: undefined, json: [ [Object], [Object] ] },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { '0': [Object] }
},
code: 50035,
status: 400,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1254637442628321361/guilds/1254264050658054204/commands'
}
Kevinnnn
Kevinnnn5mo ago
again, those types in options have to be either an enum or number
Jereme
JeremeOP5mo ago
what
Kevinnnn
Kevinnnn5mo ago
import { ApplicationCommandOptionType } from 'discord.js'

options: [
{
type: ApplicationCommandOptionType.String
}
]
import { ApplicationCommandOptionType } from 'discord.js'

options: [
{
type: ApplicationCommandOptionType.String
}
]
something like that
Want results from more Discord servers?
Add your server