Add / Remove reaction event no longer firing Discord.js v13 - discord.js

Good morning everyone,
I am currently running into one pretty irritating issue with getting a users messages from before the bots launch. I have been able to do this in the past (a few months ago), but it seems they have replaced the Intents.FLAGS approach for GatewayIntentBits. This has not been to complicated to change, but some problems have occurred.
One of the biggest issues, and the reason for this question is that even though I contain data in my intents that would allow for reading of reactions, as well as adding partials (I read it may help online). This does not seem to fix the issue.
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers], partials:["Message", "Channel", "Reaction"]})
. . .
client.on('messageReactionAdd', _ => {
console.log('a reaction has been added');
});
client.on('messageReactionRemove', _ => {
console.log('a reaction has been removed');
});
I know this isn't allot to go off of, but I have tested it with barely anything in my application and I still run into this error. Is this a known issue with the change to GatewayIntentBits? I would love to continue working on this bot.
Thank you for any assistance you may be able to provide.
EDIT: I have managed to get the reactions to work on the application now. I have not even started touching those old messages, and its working. Thank you for your help. My best bet of why its working is that the messages needed to be resent with the partials and intents specified above. I dont know why this didnt work before, but whatever.

Your gateway intent bits are fine, you need to do something similar to that for the partials as well, you need to import partials from discord.js and use them like that.
const { Client, Partials } = from 'discord.js';
const client = new Client({
intents: [],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
});

Related

Discord.js - Delete all channel by running Discord-Bot without a command

Hey i need for a project a tool to delete all channsl on a Discordserver via a Discord.js Bot.
i got one with handlers and this is my "event code" but dosent work.
Discord.js v14
const client = require("../../index");
module.exports = {
name: "blacksheep"
};
client.on("ready", () => {
var server = Client.guilds.get('1045245227264397382');
for (var i = 0; i < server.channels.array().length; i++) {
server.channels.array()[i].delete();
}})
i dont find the right way to get it worked. thx <3
Then i start the bot all Channels should be deletet without any command.
You need to include error messages or what the results of running this code was for us to actually help you, but for now I'm going to assume that everything in your bot and bot event handlers is working except for the last three lines that loop through the channels and delete them. If that's the case, then you just need to change those lines to something like this (replace your for-loop block with this):
server.channels.cache.forEach((channel) => {
channel.delete();
});
This accesses the server's channel cache, which is a collection, and so it uses the collection's forEach function to loop through all the channels, and then calls each of the channels' delete() functions to delete them.
Note that you may experience severe ratelimiting when doing this, because Discord has heavy ratelimits on requests to server channels.

Why doesn't my welcome message in discord.js work?

i have tried a lot of different ways but this seemed the most used and successful! But it doesn't seem to work for me? I don't need an embed just a simple message. How do i do this correctly?
client.on('guildMemberAdd', async newMember => {
const welcomeChannel = newMember.guild.channels.cache.find(channel => channel.id === 'my channel id is here')
welcomeChannel.send('welcome we hope you have fun')
})
I've tried your code on myself, it is working exactly just as you intended, so I'm assuming that you might not have put the correct intent. Now discord bot need specific intent (depends on what you are trying to do) to work correctly .
And in your case, you are probably missing the "GUILD_MEMBERS" intent. Change it like:
const client = new Client({
intents: 'GUILD_MEMBERS',
})
Also, in case if you are building a local bot and you don't care about intent or you just simply got annoyed by it.
You can also use
const client = new Client({
intents: 32767,
})

Discord Missing Intent Error on discord.js

Im having trouble launching my code for the past 6 hours it was working fine yesterday but it doesnt seem to work any more i keep on having an error that says ('CLIENT_MISSING_INTENT')
this is my starting code i dont understand what i am doing wrong
const Discord = require('discord.js'),
welcome = require('./welcome'),
mute = require('./mute'),
unmute = require('./unmute'),
mongoose = require('mongoose'),
Levels = require("discord-xp")
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
You're quite literally missing an Intent. As you're probably already aware based on your code, v13 of discord.js requires you to add certain Intents to avoid processing power being thrown away to features not used.
You can look at all Intents available here, and try to add a few of them to see which one you need. Based on your code I can't see which one you're missing.

Retrieve all members from specific channel in Discord

I have been trying different ways to retrieve the current list of members in a specific channel (e.g. 'networking'). But I am only get one, the actual bot user inside the channel, but nothing else.
This is the latest version of the code I am trying.
client.channels.cache.filter((c) => c.name === 'networking').forEach(channel => {
channel.fetch().then((channel) => {
console.log(channel.name);
for (let [snowflake, guildMember] of channel.members) {
console.log(`${guildMember.displayName} (${guildMember.id})`);
}
});
});
It's probably something to do with caching but I'm just not able to find the right sequence. Any help would be appreciated.
Thank you Tyler2P for the answer. You were absolutely right. Membership intents were disabled by default. I have lost so much time on this :) Thanks a million.
For everyone who gets to this question. Solution is so simple as enabling the "Server Members Intent".
Bot configuration in Discord Application page

Creating a Discord bot to notify people when to certain text on a website has changed

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = '';
bot.on('ready', () =>{
console.log('This bot is online');
})
bot.on('message', msg=>{
if(msg.content === "?rates"){
msg.reply('.')
}
})
bot.login(token);
This is what I have so far it is very basic, I understand, I'm just trying to get some sort of idea how to process. What I want is as soon as a website gets updated or changed. I would like it to tag everyone and in a certain channel and specifies what has changed. I know this will be a long process but I'm in for the ride :) would appreciate any help.
You need a webhook on the website and listen to it with your bot, if you have control over the site, this may help you, otherwise you could look if the site has one or perhaps ask an owner.
A probably working but not very nice (and not very clean) solution would be to save the text of the website every 5 seconds or so and compare it to the previous save. If it changed, you notify the members through sending a message.

Resources