#v13 to v14

1 messages · Page 1 of 1 (latest)

regal arch
#
const BaseEvent = require('../../utils/structures/BaseEvent');
const { REST, Routes, Collection } = require('discord.js')
const StateManager = require('../../utils/StateManager');
const path = require("path");
const fs = require("node:fs");
require('dotenv').config({ path: '../.env' });

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


module.exports = class ReadyEvent extends BaseEvent {
    constructor() {
        super('ready');
        this.connection = StateManager.connection;
    }
    async run(client) {
        console.log(client.user.tag + ' has logged in.');

        client.slashCommands = new Collection();
        client.guildCommandPrefixes = new Collection();

        // start of ( / ) cmds refreshing

        // End of section

        // Start of checking if all Guild-Ids are in the database
        
        // End of section
        // Start of getting all data out of the database

        // End of section

        // some code
    }
}
snow edge
regal arch
#

thats my ready.js, it handels all the commands and interactions...

#

or do you want the bot.js

snow edge
#

And that's not the way to do it I'm afraid.
Things are different in v14.
You should use a separate deploy-commands.js file like the new guide suggests

regal arch
#

okay, ig i keep it in v13...

snow edge
#

Your choice if you want to, but I advise against it

regal arch
#

is it hard to switch?

snow edge
#

No actually. If you were on v12 yes.
And depending on the size of the codebase

regal arch
#

or is it more or less a copy and paste and re-arranging the code

regal arch
#

excl. commands

#

but the commands stay the same (?)

snow edge
#

The pain will be worth it trust me.
v13 will be deprecated sooner or later in favor for v14.

Major changes are mentioned in the guide as well I linked you.
If you follow that exactly and iron out the errors your're get you're good to go

#

I can feel the pain because I myself translated a whole JS project to TS alone with over a few hundred files teri_ded
But now I'm stress free and just maintaining the code.

regal arch
#

why do they change it all the time :(((

snow edge
regal arch
snow edge
#

With new discord changes it's necessary

#

You won't be able to do much in the v13 I'm afraid

#

And new updates to Discord is only available in v14

#

Like the new name change in the future dJS update

#

So on and so forth

regal arch
# snow edge With new discord changes it's necessary
const { MessageEmbed, SlashCommandBuilder } = require("discord.js");

module.exports = {
    data: new SlashCommandBuilder()
        .setName('info')
        .setDescription('Info about the bot'),

when i do that, i get the error that SlashCommandBuilder is not a constructor... idk what to do, its the same style as on the discordjs site..

#

v13 to v14

regal arch
# snow edge npm ls discord.js
jonas@MacBook-Air-von-Jonas fr24db % npm ls discord.js
orange.db@1.2.7 /Users/jonas/Coding/fr24db
└── discord.js@14.11.0

jonas@MacBook-Air-von-Jonas fr24db % 
snow edge
#

strange.... wtf accordingtodagmarsama
Also it's EmbedBuilder now. Use that instead of MessageEmbed.

#

Can you show the full error if possible

regal arch
#

okay... i uninstalled and installed it, its working now, but other problems are there still...

snow edge
#

And yeah removing and uninstalling is the better way.... I think the guide says it

regal arch
#

redefining flags, but thats no problem 😄

snow edge
#

Good luck then ! seele_cheer
Keep it up.

regal arch
#

thanks for your help

snow edge
regal arch
regal arch
# snow edge

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.
what does that mean and how to fix it? it happend as soon as i changed from intent to gatewayintentbits

regal arch
#
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
const {Client, GatewayIntentBits, Collection, REST, Routes} = require('discord.js');
const {registerCommands, registerEvents} = require('./utils/register');
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildMemebers,
    ],
});
snow edge
#

Hmm

#

Gimme a sec

regal arch
#

sure thing

snow edge
#

The problem is from where it's getting the undefined flag when you don't have something like that

regal arch
#

okay i removed all npm packages and installing them rn... i made a backup maybe its working

#

still the same error...

snow edge
#

Copy paste the entire error here

regal arch
#

sure

#
[Running] node "/Users/jonas/Coding/fr24db/src/bot.js"
/Users/jonas/Coding/fr24db/node_modules/discord.js/src/util/BitField.js:172
    throw new DiscordjsRangeError(ErrorCodes.BitFieldInvalid, bit);
    ^

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.
    at IntentsBitField.resolve (/Users/jonas/Coding/fr24db/node_modules/discord.js/src/util/BitField.js:172:11)
    at /Users/jonas/Coding/fr24db/node_modules/discord.js/src/util/BitField.js:167:54
    at Array.map (<anonymous>)
    at IntentsBitField.resolve (/Users/jonas/Coding/fr24db/node_modules/discord.js/src/util/BitField.js:167:40)
    at new BitField (/Users/jonas/Coding/fr24db/node_modules/discord.js/src/util/BitField.js:33:38)
    at new IntentsBitField (/Users/jonas/Coding/fr24db/node_modules/discord.js/src/util/IntentsBitField.js:9:1)
    at Client._validateOptions (/Users/jonas/Coding/fr24db/node_modules/discord.js/src/client/Client.js:494:25)
    at new Client (/Users/jonas/Coding/fr24db/node_modules/discord.js/src/client/Client.js:78:10)
    at Object.<anonymous> (/Users/jonas/Coding/fr24db/src/bot.js:5:16)
    at Module._compile (node:internal/modules/cjs/loader:1254:14) {
  code: 'BitFieldInvalid'
}

Node.js v18.14.1

[Done] exited with code=1 in 0.213 seconds

snow edge
#

bot.js:5:16

#

What's here ?

#

By that I mean what's at line 5 of bot.js ?

regal arch
snow edge
#

Members

#

Not Memebers

#

lmao

#

The importance of paying attention to what VS Code points out

regal arch
#

i feel so stupid rn

snow edge
regal arch
#

lmao its working now, still some things to fix but the hard work is over hahaha

#

thanks haha

snow edge
#

Happy to help. Ping me if I don't respond immediately

regal arch
#

Sure

#

Thanks

snow edge
#

console.log(Successfully reloaded ${data.length} application (/) commands.);

#

What does this line say ?

#

0 ?

regal arch
#

4

#

i have currently 4 activated, the others are currently offline

snow edge
#

Restarting DC also fixes that sometimes.... also takes some time in rare cases

#

If even still same then code issue somewhere

regal arch
#

Okay, I’ll try that later I have a train to catch but I hope that’ll work

regal arch
#
const { MessageEmbed, SlashCommandBuilder } = require("discord.js");

module.exports = {
    data: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('latency'),

    async execute(client, interaction) {
        await interaction.reply({
            content: "pinging..."
        });
        const Botlatency = Math.abs(Date.now() - interaction.createdTimestamp);
        const Apilatency = client.ws.ping;
        await interaction.editReply({
            content: `Bot latency: \`${Botlatency}ms\`, Api latency: \`${Apilatency}ms\` `
        });
    }
}

this is my code

#

i debugged it with a break point and it never reached it...