Problem with Intents updating discord.js version 14 [duplicate] - javascript

This question already has answers here:
Discord.js v13 code breaks when upgrading to v14
(1 answer)
Discord.Js: TypeError: Cannot read properties of undefined (reading 'FLAGS')
(1 answer)
Discord.js reads Intents as undefined
(2 answers)
Closed 14 days ago.
i am having a problem when i want to update to discord.js version 14 this is my discord.js client code
const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.FLAGS.GUILDS,
GatewayIntentBits.FLAGS.GUILD_MEMBERS,
GatewayIntentBits.FLAGS.GUILD_BANS,
GatewayIntentBits.FLAGS.GUILD_INTEGRATIONS,
GatewayIntentBits.FLAGS.GUILD_WEBHOOKS,
GatewayIntentBits.FLAGS.GUILD_INVITES,
GatewayIntentBits.FLAGS.GUILD_VOICE_STATES,
GatewayIntentBits.FLAGS.GUILD_PRESENCES,
GatewayIntentBits.FLAGS.GUILD_MESSAGES,
GatewayIntentBits.FLAGS.GUILD_MESSAGE_REACTIONS,
GatewayIntentBits.FLAGS.GUILD_MESSAGE_TYPING,
GatewayIntentBits.FLAGS.DIRECT_MESSAGES,
GatewayIntentBits.FLAGS.DIRECT_MESSAGE_REACTIONS,
GatewayIntentBits.FLAGS.DIRECT_MESSAGE_TYPING,
],
partials: ["CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION", "USER"],
allowedMentions: {
parse: ['users', 'roles'],
repliedUser: false
}
});
client.setMaxListeners(0)
module.exports = client;
the error i get on console
GatewayIntentBits.FLAGS.GUILDS,
^
TypeError: Cannot read properties of undefined (reading 'GUILDS')
i had discord version 13 and i updated the client but i still get a error on flags.guilds.

As your error already states, FLAGS is not a property of GatewayIntentBits
You can find the official documentation of braking changes here
So according to the official docs, GatewayIntentBits.FLAGS.GUILDS should be GatewayIntentBits.Guilds

Related

Discord.js v14 Permissions | RangeError [BitFieldInvalid]: Invalid bitfield flag or number: STREAM

I using discord.js V14 to check if a voice channel has streaming permissions enabled.
I tried this but it's not working.
if (voiceChannel.permissionsFor(voiceChannel.guild.id).has("STREAM"))
It gives me the following error:
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: STREAM.
btw, this code is working perfectly with the "Connect" permission.
In v14, you can't use STREAM or other strings, you should use the enums from PermissionFlagsBits:
const { PermissionFlagsBits } = require('discord.js')
// ...
if (voiceChannel.permissionsFor(voiceChannel.guild.id)
.has(PermissionFlagsBits.Stream)
)
You can view all the available permissions here: PermissionFlagsBits
Related: Errors with enums in discord.js v14
Well, did you try using Stream instead of STREAM ? I can't see anything else if it's working using Connect.

Discord.js intents | Not working Discord v14 Node.js v19.3.0 [duplicate]

This question already has an answer here:
Discord.js v13 code breaks when upgrading to v14
(1 answer)
Closed last month.
it keeps giving me an error every time I run it and it's always a different error after I change the code
This is my method that I found, Im coding this in the latest version of node.js and discord.js
const { Client, Intents } = require('discord.js');
const fs = require('fs');
// Create a new client
const client = new Client({
intents: new Intents(Intents.ALL),
});
My error for this is TypeError: Cannot read properties of undefined (reading 'ALL')
I tried this too
const client = new Client({
intents: new Intents([
'GUILDS',
'GUILD_MESSAGES',
'MESSAGE_CONTENT',
'GUILD_MEMBERS',
]),
});
And still it gives me an error TypeError: Intents is not a constructor
I don't know any other way to fix, this can someone help me?
By adding this
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
And adding this to the beginning
const { Client, Events, GatewayIntentBits } = require('discord.js');

Check if bot has permissions in a specific channel discord.js v14

I'm trying to figure out how to check if my bot has the right ViewChannel and SendMessages in a certain channel. I tried discord.js v13 variant with if(!interaction.guild.me.permissionsIn(channel).has("VIEW_CHANNEL)). Then upgraded it to discord.js v14. if(!interaction. guild.members.me.permissionsIn(channel).has([PermissionsFlagsBits.ViewChannel, PermissionsFlagsBits.SendMessages]))
But there I keep getting the same error:
TypeError: Cannot read properties of undefined (reading 'id') at GuildMemberRoleManager.get cache [as cache] (C:\Users\sdamz\OneDrive\Desktop\dcbot v2\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:37:101) ...
Already did it with just
if(!interaction.guild.members.me.permissions.has([PermissionsFlagsBits.ViewChannel, PermissionsFlagsBits.SendMessagesl])
but got the same error.
I would appreciate an answer!
You need the Guilds intent
const client = new Client({
intents: [GatewayIntentBits.Guilds, /* other intents */]
})
The problem is here. It tries to set the everyone role, but it's uncached, without Guilds intent.
I was also struggling with this problem and this is what worked for me:
(interaction.guild.members.me).permissionsIn("Your_Channel_ID").has(PermissionsBitField.Flags.SendMessages);

Discord Bot not going online [duplicate]

This question already has answers here:
Why am I getting a ReferenceError: AbortController is not defined in Discord.js v13?
(3 answers)
Closed 1 year ago.
require("dotenv").config();
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
client.on("ready", () => {
console.log("bot is ready");
});
client.login(process.env.DISCORD_BOT_TOKEN).catch((e) => {
console.log(e);
});
OUTPUT
HTTPError [ReferenceError]: AbortController is not defined
at RequestHandler.execute (g:\goofy-translator\node_modules\discord.js\src\rest\RequestHandler.js:172:15)
at RequestHandler.execute (g:\goofy-translator\node_modules\discord.js\src\rest\RequestHandler.js:176:19)
at RequestHandler.push (g:\goofy-translator\node_modules\discord.js\src\rest\RequestHandler.js:50:25)
at async WebSocketManager.connect (g:\goofy-translator\node_modules\discord.js\src\client\websocket\WebSocketManager.js:128:9)
at async Client.login (g:\goofy-translator\node_modules\discord.js\src\client\Client.js:245:7) {
code: 500,
method: 'get',
path: '/gateway/bot',
requestData: { json: undefined, files: [] }
}
The error is caused by client.login() method.Already triple checked the bot token and all seems fine. The problem isn't in the enviroment varible either, because also doesn't work when I pass the token directly.
[Resolved]
The problem was the node version, discord.js requires v16 min
Since version 13 of Discord.js, the library requires that you use a more recent Node.js version. According to the docs, you need to use Node.js version v16.6.0 or higher.
For more information about how to change your node version, or use multiple node versions, see NVM for Windows or NVM for Linux depending on your OS.

my discord.js bot doesn't reply to a user message even if there isn't any error [duplicate]

This question already has answers here:
message event listener not working properly
(2 answers)
Closed 1 year ago.
my discord.js bot has version 13.1.0, and my node's version is 16.7.0. I entered these commands in the terminal : npm init to create package.json and npm install discord.js to install discord package.
I writed the code in index.js, and I created config.json to put the token there.
When I run then the code it shows me 'Ready!' in the console and being online in Discord. I also can change the status and the activity of the bot without a problem. The problem here is the bot doesn't send or reply to a message.
Here's the code bellow
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.on ('messageCreate', (message) => {
if (message.content === 'hello') {
message.reply('Hello')
};
});
client.login(token);
this's config.json's code just in case.
{
"token": "my_bot_token!"
}
The issue is caused by missing intents. To listen to messages, you need to specify the GUILD_MESSAGES flag:
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

Categories

Resources