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);
#Hello sorry im new to this but did i do this right
100 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- 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!
Some of this looks like v13 code, not v14
@clear tangle 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);
The Intents have changed
no, nothing here is fixed
Are you using ChatGPT or something?
If you dont mind me asking, where are you getting the outdated code from?
I recommend following our guide for the most up to date code and references https://discordjs.guide/#before-you-begin
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
so
That is quite a lot and our guide definitely doesnt cover all of that
ik
it is for my server
if you are a beginner those might be little too hard for you
i wouldn’t suggest you discourage them as that’s not helpful
Im not discouraging him lol
You literally told him to quit
shared my opinion
Please leave this thread if you have no intention of helping people use discord.js
👍🏻
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
some one said py is better
tf is the new intents
Sure, the video is fine, it shows you how to start the basics for your bot
i got all that i just need the intents
The intents didn't change between v13 and v14, they just changed what name they are under
@gray shoal 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',
});
ok
so i made the index to were it will auto make my command
is this something you made or some package/chatgpt thing? djs doesn't have anything that automatically makes commands
no like it regesters and it is from my old bot that my frinde fix like 3 things
uhh what
there is something similar in the guide, you can try to use the one you have or make a new one from the guide
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
});
},
};
now i got to make a embed maker
witch im go do
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 });
},
};
i think i did good
just got to waait for my bot to chatch
option types aren't uppercase strings anymore, they are either enums or numbers
yes, it is a type you have to import
otherwise you can use the corresponding numbers
no fo it to work do i have to export it
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
what guide are you using ^^
you're on discord.js v14 but the code you've been providing has been v13
That is why I tagged how to create an embed, #1255010013815242793 message
could you rephrase that maybe? I have no idea what youre asking here
ii cant find how the embed thing im making is made
what are you looking for that is different from what the guide provides?
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 });
},
};
anddddd what does it not have?
sorry but im new to v14 and stuff
I'm confused on what you say isn't in the guide that is in your code
string
For options or the embed?
both
we'll start with options
how are you parsing your slash commands data when updating your slash commands?
huh
when you upload slash commands to discord, what code are you using to do that
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 });
}
});
and where is your deploy-commands.js?
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'
}
again, those types in options have to be either an enum or number
what
here if you wanna look at it all rq
https://prod.liveshare.vsengsaas.visualstudio.com/join?FCF2AFD2FB20FE0E4D9766D0B2D183681138
import { ApplicationCommandOptionType } from 'discord.js'
options: [
{
type: ApplicationCommandOptionType.String
}
]
Additional Information: Updating from v13 to v14
