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

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();
});

Related

Obtening reactions in discord js 13 not working

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.

How do I make my discord bot auto respond to any message

What I am trying to do is set up an autoresponse discord bot that adds a reaction to any message that is being sent,in a specific channel. I cannot figure out why it is not showing up in discord.
It's very simple, just add a message event listener, validate if the channel id is the one you want it to be, and then use the .react method. For example:
client.on('message', message => {
if (message.channel.id !== 'channel id here') return;
message.react('emoji here')
// if you want to use a custom emoji put it's id there instead.
})

Deleting all messages from somebody on Discord

I'm trying to make a bot that will delete all messages from another bot. A bot malfunctioned and spammed a whole bunch of messages, and so I want to delete the messages, which would take absurdly long.
You can fetch all messages from the channel. Then filter it by userID and delete
In your post you said that your bot spammed the messages so this code is for removing your bot's messages
message.channel.messages.fetch().then(messages => {
const botMessages = messages.filter(msg => msg.author.bot);
message.channel.bulkDelete(botMessages);
})

Is it possible to make a bot limit the amount of a specific reaction on a specific message?

My friend is creating an event where the first 24 people to react to their message are entered. Is there a way to make it so that after 24 reactions, a bot will remove any new reactions?
Well, you can just delete the message after. However what you can do is lock the permission to add new reactions, and clear all the reactions on that message so that no one can add new ones. If you're talking about wanting to keep the existing reactions. You can do this.
<Client>.on("messageReactionAdd", (reaction, user) => { //on reaction
if(reaction.message.id == "you_reaction_message_id" && reaction.users.size >= 24) { //if the message is the right one, and if it's equal to or more than 24 users on that reaction.
reaction.users.remove(user); //MASTER
reaction.remove(user); //STABLE
}
})
Again not the best idea but. It works.

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