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

100 messages · Page 1 of 1 (latest)

fervent grove
#
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);
copper sierraBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • 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!
clear tangle
#

Some of this looks like v13 code, not v14

placid lindenBOT
#

guide Additional Information: Updating from v13 to v14
read more

fervent grove
#

@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);
clear tangle
#

The Intents have changed

#

no, nothing here is fixed

#

Are you using ChatGPT or something?

fervent grove
#

no

#

i put // Replace with your Discord server ID so i know

clear tangle
#

If you dont mind me asking, where are you getting the outdated code from?

fervent grove
#

bc im still learnign and it is notes

#

youtube

#

and myself

clear tangle
fervent grove
#

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
clear tangle
#

That is quite a lot and our guide definitely doesnt cover all of that

fervent grove
#

ik

urban mulch
#

I would quit coding discord bot and do something more useful

#

just saying

fervent grove
urban mulch
#

if you are a beginner those might be little too hard for you

gray shoal
#

i wouldn’t suggest you discourage them as that’s not helpful

urban mulch
#

Im not discouraging him lol

clear tangle
#

You literally told him to quit

urban mulch
#

shared my opinion

clear tangle
#

Please leave this thread if you have no intention of helping people use discord.js

urban mulch
#

👍🏻

clear tangle
#

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

fervent grove
#

tf is the new intents

vague sundial
#

Sure, the video is fine, it shows you how to start the basics for your bot

fervent grove
vague sundial
#

The intents didn't change between v13 and v14, they just changed what name they are under

placid lindenBOT
fervent grove
#

@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',
});
placid lindenBOT
fervent grove
#

ok

fervent grove
vague sundial
fervent grove
#

no like it regesters and it is from my old bot that my frinde fix like 3 things

gray shoal
#

uhh what

vague sundial
#

there is something similar in the guide, you can try to use the one you have or make a new one from the guide

placid lindenBOT
fervent grove
#

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

placid lindenBOT
#

guide Popular Topics: Embeds - Using the embed constructor
read more

fervent grove
#

i found it

fervent grove
# vague sundial there is something similar in the guide, you can try to use the one you have or ...

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

vague sundial
#

option types aren't uppercase strings anymore, they are either enums or numbers

fervent grove
#

what

#

wait do i have to export it

vague sundial
#

yes, it is a type you have to import

#

otherwise you can use the corresponding numbers

fervent grove
#

no fo it to work do i have to export it

placid lindenBOT
#

guide Slash Commands: Advanced command creation
read more

twin bone
#

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

vague sundial
#

what guide are you using ^^

#

you're on discord.js v14 but the code you've been providing has been v13

fervent grove
#

oh dam

#

im on the one you give im using some stuff from my old bot from v13

vague sundial
fervent grove
#

i can find it

#

as of what it is to do what im doing

vague sundial
#

could you rephrase that maybe? I have no idea what youre asking here

fervent grove
#

ii cant find how the embed thing im making is made

vague sundial
#

what are you looking for that is different from what the guide provides?

fervent grove
#

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 });
    },
};
vague sundial
#

anddddd what does it not have?

fervent grove
#

sorry but im new to v14 and stuff

vague sundial
#

I'm confused on what you say isn't in the guide that is in your code

fervent grove
#

string

vague sundial
#

For options or the embed?

fervent grove
#

both

vague sundial
#

we'll start with options

placid lindenBOT
#

guide Slash Commands: Advanced command creation
read more

fervent grove
#

wait did i do it right

#

or

#

bc im dumb

vague sundial
#

how are you parsing your slash commands data when updating your slash commands?

fervent grove
#

huh

vague sundial
#

when you upload slash commands to discord, what code are you using to do that

fervent grove
#
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 });
    }
});
vague sundial
#

and where is your deploy-commands.js?

fervent grove
#
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'
}
vague sundial
#

again, those types in options have to be either an enum or number

fervent grove
#

what

fervent grove
vague sundial
#
import { ApplicationCommandOptionType } from 'discord.js'

options: [
  {
    type: ApplicationCommandOptionType.String
  }
]