Is there a way to add all intents to a Discord.js bot in v14? - discord.js

I'm trying to create a new client with all intents but nothing I have found online has solved the issue. Here is my code:
const Discord = require('discord.js')
const client = new Discord.Client({ intents: 7796 })

Related

TypeError: Cannot read properties of undefined (reading 'FLAGS') discord.js

so this is my bot code
const Discord = require("discord.js")
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES] });
client.on("ready", () => {
console.log('Logged in as ${client.user.tag}!')
console.log("Bot is online!")
})
client.on("message", msg => {
if (msg.content === "ping") {
msg.reply("no1se");
}
})
client.login("my token")
The error i get is this:
TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (/home/runner/no1seAlerts-1/index.js:4:47)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
Hint: hit control+c anytime to enter REPL.
(node:2004) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
yea so im trying to make a discor dbot everytime when i try to run it and make it online i get this error code i have no idea what to do and i would really appreciate any help thank you!
Assuming you are using discord.js v13, you can try and change your client to:
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })
You should replace Intents with IntentsBitField
In your example it would be:
const client = new Client({ intents: [IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages] });
This was changed with version 14 of discord.js I believe.
Alternatively you can use GatewayIntentBits:
const client = new Client({ intents: [GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages] });
More information here
Hope this helps!

How can a bot read embed messages sent by another bot and post a message if it contains a specific content?

I'm trying to code a Discord bot that would read embed messages sent by another bot and ping a specific role if the embed contains '(FREE)' in the title, as displayed here:
https://i.stack.imgur.com/kPsR1.png
Unfortunately, my code produces nothing. I don't run into any error, the bot simply doesn't post a message when conditions are matched to do so — yet it is online and has the permissions to post messages in the channel.
Any help would be really appreciated. I went through all the questions related to this topic on SO, but I couldn't find a working solution to my issue. I'd like to mention that I'm a beginner in JS.
Thank you so much.
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_WEBHOOKS"] })
client.on('ready', () => {
console.log(`Logged in...`);
});
client.on('messageCreate', (message) => {
if (message.embeds) {
const embed = message.embeds[0]
if (embed.title === '(FREE)') {
return message.channel.send('#Free mint')
}
}
})
Edit: I believe my question is different from the one suggested in the comment as I'm looking for specific content in the embed.
I managed to make the bot work with the following code, thanks #Gavin for suggesting it:
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_WEBHOOKS"] })
client.on('ready', () => {
console.log(`Logged in...`);
});
client.on('messageCreate', message => {
for (let embed of message.embeds) {
if (embed.title.includes('FREE')) {
return message.channel.send("<#&" + roleId + ">")
}
}
});

Discord.js 'CLIENT_MISSING_INTENTS' Error

I am trying to make my Discord bot appear online, but I am getting an error
Code:
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready' , () => {
console.log('Bot is online');
});
client.login('My token');
Can anyone point me in the right direction?
Intents were introduced in discord.js v13 and ensure that the bot only does what it intends to do - i.e. it doesn't waste processing power.
//example from the official Discord.js guide
const { Client, Intents } = require('discord.js');
const myIntents = new Intents();
myIntents.add(Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_MEMBERS);
const client = new Client({ intents: myIntents });
client.login('mytoken');
The docs are always a good place to look first.

I want to get System Messages Channel in discord.js v12

I want to get SystemChannel. I am using discord.js v12, this is what I have so far:
bot.on('guildMemberAdd', member => {
// I want to get this channel, not by name
[System Messages Channel][1]
const channel = (getDefaultChannel)
if(!channel) return;
channel.send(`hello ${member}!`);
});
You can get the SystemChannel by using member.guild.systemChannel, or member.guild.systemChannelID in case you want the channel's ID, in your guildMemberAdd event.
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
// Get the "System Messages Channel"
const systemMessagesChannel = client.guilds.cache.first().systemChannel;
// Send a message to the channel
systemMessagesChannel.send('Hello from the bot!');
});
client.login('YOUR_BOT_TOKEN_HERE');

Could not leave a discord guild

I'm trying to make my bot leave any guilds if the guilds size reaches 2 guilds
I tried everything from the Discord.js docs using leave()
// Here is my code on guildCreate.js event
const Discord = require('discord.js');
const client = new Discord.Client();
let guildArray = client.guilds.array();
module.exports = async function (msg,guild) {
if(guildArray.size > 1)
await guild.leave()
};
It should works and leave the guild because the size is more than 2 guilds but it do nothing .
I think you want something like this if I am right:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
let guildnumber = client.guilds.size;
while(guildnumber > 2 )
{
client.guilds.first().leave();
guildnumber--;
}
});
client.log(token);
You can put it into ready and/or guildAdd as guildAdd only emits when your bot gets added to a guild and is online so you should check if your bot was added during it was offline

Resources