const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds, //all problem here
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
],
});
client.login("TOKEN");
You get this problem because you are accessing privileged intents. To fix this go to https://discord.com/developers/applications/ click on your bot. Then go to the section that says bot and scroll down to Privileged Gateway Intents. Enable server members and message content intent. After that it should be fixed.
Related
my guildBanAdd event on discord.js v14 doesn't trigger whenever I ban a user, same as the messageDelete event. Do I need to give my bot any specific permission aside the adminstrator permission it has or is there an Intent that is missing in the client
other events such as interactionCreate and messageCreate works just fine
`
module.exports = {
name: "guildBanAdd",
async execute(guild, user, client) {
console.log('I was called: guildBanAdd');
},
};
`
`
module.exports = {
name: "messageDelete",
async execute(message, client) {
console.log(`delete logs: ${message}`);
},
};
`
my client Intents
`
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
`
I have also enabled all three Privileged Gateway Intents on the discord application dashboard as well.
Thank you.
I tried banning a user and expected something to be logged but nothing showed, I also tried deleting a user content and nothing showed
I'm trying to make a selfbot and before receiving messages saying that's against Discord ToS, I take that risk. My bot sends messages only to people it already has a DM channel opened with, probably because members aren't cached.
I want my bot to send message to everyone in my server. How do I cache members on a selfbot?
Code:
const guild = client.guilds.cache.get("id");
if(!guild) return;
guild.members.fetch();
guild.members.cache.random().createDM().then((dm => {
dm.send("Dont forget to verify !").catch(e => console.log('error'))
})).catch(() => {});
console.log("message sent");
Server Members Intent Image
Image above shows example to this answer;
Did you enable SERVER MEMBERS INTENT when creating your Discord bot?
https://discord.com/developers/applications/"ClientId"/bot
And/or did you create a new discord client with the GUILD_MEMBERS intent?
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.GuildMembers
]
});
And whether or not you know the risks, you should NOT be using self bots.
So I've been working on a discord bot I made for about a year, although I stopped for a bit a couple months ago. Anyway, I was getting back into it, and last night a made a "-say (something)" command for my bot. It was working out just fine, but today, I check up on the bot again, and I start getting an error about how I didn't state valid intents, but this is my code (for the client intents).
const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"]});
If anyone knows what I'm doing wrong, I'd be super grateful if you could let me know.
Thanks!
const { Client, GatewayIntentBits , Partials } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
)}
you need to use this if you are on v14
I made a discord bot and i have no idea what's wrong with my code i mean look:
const Discord = require("discord.js");
const client = new Discord.Client({
intents: [
"GUILDS",
"GUILD_MESSAGES"
]
});
client.login('you thought haha')
I tried various tutorials but it's still not working
It's looking like about the intents and there's simple mistake as i've seen. If you wan't to open all intents i recommend you this;
const client = new Discord.Client({
intents: new Discord.Intents(32767)
});
If you wan't specific intents then you should make them like;
const client = new Discord.Client({
intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES]
})
Also don't forget to open your intents from bot section on your developer panel!
More info here on docs.
I'm assuming you have already installed Node.js and discord.js, and also have a bot setup.
If you check discord.js Guide, they provide you the following code to start your bot:
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready!');
});
// Login to Discord with your client's token
client.login(token);
Then, open your terminal and run node index.js (assuming that your file name is index.js) to start the process. If you see "Ready!" after a few seconds, you're good to go!
I strongly recommend for you to follow this guide, it helped me a lot with the first steps with the discord bot.
Also, make sure that you have the right scopes selected for your bot:
I think the error is on the client declaration. You have to capıtalize the first letter of "intents". So the code becomes:
const Discord = require("discord.js");
const client = new Discord.Client({
Intents: [
"GUILDS",
"GUILD_MESSAGES"
]
});
client.login("your token here");
And also please make sure that on your discord developers page you have your intents turned on.
I'm trying to get all users connected to a voice channel on my server. When someone talks to a bot in #general, I want to get the users inside Voice Channel 1.
I'm using Node 17 and DiscordJS 13.
This is my code:
message.guild.channels
.fetch(channelID, { cache: false, force: true })
.then((channels) => {
console.log(channels.members);
});
Also, I tried this one:
let voiceChannel = client.guilds.cache
.get(process.env.DISCORDJS_GUILD_ID)
.channels.cache.get(process.env.DISCORDJS_CHANNEL_ID);
let membersInChannel = voiceChannel.members;
console.log(membersInChannel);
But, it always returns the voice channel users that joined when I start the node app. If someone leaves the voice channel, it keeps showing him in the console.log when I say something to the bot in #general. How can I achieve this?
I've had the same problem. Although I added { force: true } as the option in fetch, it always showed the same number of members when I started the app, ignoring the ones who joined/left the channel.
Enabling the GUILD_VOICE_STATES intent solved this. So don't forget to add it to your client:
const { Client, Intents } = require('discord.js');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_VOICE_STATES,
],
});