Obtening reactions in discord js 13 not working - discord.js

I am trying to create a bot for my-self that count reactions but when i try using this code to obtain all reactions it doesnt work at all. If any of you have an idea.
client.on('messageReactionAdd', (reaction, user) => {
console.log(reaction.emoji.name);
})
I tried placing emojis and all but it never printed anything.

Related

Leave a Guild if there are more bots then members

So I have been trying to make a way to have my Discord bot leave a guild if there are more bots then Members, I have looked everywhere and can't find anything about it and people are not very helpful, Can I get some help on this?
In discord.js v12 you do it like this:
const memberCount = guild.members.cache.filter((member) => !member.user.bot).size;
const botCount = guild.members.cache.filter((member) => member.user.bot).size;
if (botCount > memberCount) {
guild.leave().catch((err) => {
console.log(`there was an error leaving the guild: \n ${err.message}`);
});
}
First you'll get both the count of the actual guild members and the count of the bots. Don't forget the cache property in v12!
Then we can check which number is larger and possibly leave the guild.
You might want to run this code on <Client>.on("message", (message) => {});

Im trying to do a reaction role bot on discord

client.on('messageReactionAdd', async (reaction, user) => {
if(reaction.message.id === "731619243249893417"){
const guildMember = reaction.message.guild.members.cache.get(user.id)
if(!guildMember.roles.cache.get("692177977705889845")){
guildMember.roles.add("692177977705889845");
Im using this code, but when i react to the message it
don't give me the role, im a starter needing help, thanks u all, and sorry for my english
Bots only listen for new messages. You have to tell them to listen for an old message explicitly to get a reaction from them. Try using this code. It fetches the message when a reaction is added to that message.

How do I prevent people from adding extra reactions? Discord JS

I am making a bot and I want to limit people to four reactions on the embed. So how would I limit them to just any four reactions.
You can use Client#messageReactionAdd event, which is fired whenever a reaction is added to a message.
You can check if the message has more than 4 reactions and remove the reaction if needed.
client.on("messageReactionAdd", (MessageReaction, User) => {
if (MessageReaction.message.reactions.cache.size > 4) MessageReaction.remove();
});

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.

Is there a way to check if discord bot joins a server?

I'm making a discord bot and I want to check if it joins a server so I can set prefixes, send messages etc.
I tried searching for this but I didn't find anything that could help.
I thought it could be an event so tried something like:
client.on('join_guild', (guild) => {
prefix = "!"
});
But, of course, it didn't work.
Is there something like the code shown above?
I think you're looking for the guildCreate event. It gets triggered once your bot joins a new guild. Example code:
client.on("guildCreate", (guild) => {
// This event triggers when the bot joins a guild.
console.log(`Joined new guild: ${guild.name}`);
});

Resources