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

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.

Related

Discord Autocode reaction reply bot (not reaction role bot)

I have been using autocode.com to create some Discord bots. I have very little programming experience and found autocode to be quite easy. However, I've tried asking a question on autocode's discord that no one seems to understand or is asking.
I am trying to create a bot that replies to reactions--but does not assign roles, but instead, provides a reply--either in thread or a DM to that user who uses that specific emoji reaction.
For example, this is what I am looking to do: if there is a bot message in #channelx, userX will react to that message with a pepperoni emoji and then a pizza bot will reply back with a message either in thread or DM such as, "Hi #userx, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order".
Autocode has a bot that can react to reactions and assign roles but I can't seem to reverse engineer it give a reply, rather than assign roles.
I appreciate any assistance. Thanks!
What does autocode use? Python or node.js? If python, you can do something like this:
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('message'):
await message.channel.send('hi')
If node.js, you can do something like this:
client.on('messageCreate', msg => {
if (msg.content === 'specific message') {
msg.reply(`response text`);
}
});
I was previously a Community Hero at the Autocode Discord server. Try finding another app through this, and if none are available, the thing to do would be looking through the API's. Here's one for messaging in general, here's one for responding, and here's one for dm-ing.
Let's say, for example, I'd be making it reply to a reaction through DM:
The first thing you do is make sure the event trigger is set to message.reaction.add. This is so that the code you will write is triggered whenever a reaction is added.
Make either a switch or if statement to change what happens depending on what reaction triggers the code. In this example, I'll just use an if statement for easy explanation.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.emoji.id == '1234567890') {
await lib.discord.users['#0.2.1'].dms.create({
recipient_id: `${context.params.event.member.user.id}`,
content: `Hi <#${context.params.event.member.user.id}>, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order`
});
}
What this does is check if the thing that triggered this event has the emoji id equaling '1234567890': If it does, then it follows into that if statement, and if it does not, it skips over it.
In the future, please stay patient in the Autocode Discord server; The ones who are helping are also community members, similar to here. You may always ask the same question every now and then.

How to not send bots message edit discord.js

I have a message edit log but I want to stop sending the log if a mobs message was updated, I tried a few codes like
if(bot.oldMessage.content.edit()){
return;
}
It showed and error
cannot read property 'edit' of undefined
I then removed edit then content was undefined. The code for the message update is below.
The Code
module.exports = async (bot, oldMessage, newMessage) => {
let channels = JSON.parse(
fs.readFileSync('././database/messageChannel.json', 'utf8')
);
let channelId = channels[oldMessage.guild.id].channel;
let msgChannel = bot.channels.cache.get(channelId);
if (!msgChannel) {
return console.log(`No message channel found with ID ${channelId}`);
}
if (oldMessage.content === newMessage.content){
return;
}
let mEmbed = new MessageEmbed()
.setAuthor(oldMessage.author.tag, oldMessage.author.displayAvatarURL({dynamic: true}))
.setColor(cyan)
.setDescription(`**Message Editied in <#${oldMessage.channel.id}>**`)
.addField(`Before`, `${oldMessage.content}`)
.addField(`After`, `${newMessage.content}`)
.setFooter(`UserID: ${oldMessage.author.id}`)
.setTimestamp()
msgChannel.send(mEmbed)
}
How would I stop it from sending the embed if a bots message was updated.
Making a really simple check will resolve this issue. In Discord.js there is a user field that tells you if the user is a bot or not.
In fact, it is really recommended you add this in the "onMessage" part of your code as it stops other bots from using your bot, this is to make sure things are safe and no loopbacks/feedbacks happen, either way, you don't want a malicious bot taking advantage of your bot, which can get your bot in trouble too.
Here is what you want to do;
if (message.author.bot) return;
What this code specifically does is check if the message's author is a bot, if it returns true, it will break the code from running, if it returns a false, the code continues running.
You can do the same if you want to listen to bots ONLY by simply adding a exclamation mark before the message.author.bot like this;
if (!message.author.bot) return;
It is also possible to see what other kinds of information something holds, you can print anything to your console. For example, if you want to view what a message object contains, you can print it into your console with;
console.log(message) // This will show everything within that object.
console.log(message.author) // This will show everything within the author object (like ID's, name, discriminators, avatars, etc.)
Go ahead and explore what you can do!
Happy developing! ^ -^
That is really easy to do. All you need to do is check if the author of the message ist a bot and then return if true. You do that like this
if (oldMessage.author.bot) return;

Discord, sending a message to a different category and channel depending upon which reaction is selected

I have been working on a way within my discord server to try to automate the flow of users who want to try out for a team using bots. Currently I have adopted YAGPDB and have a role menu created in a community level (category) #general_tryouts channel with reactions to specify which game they want to pursue. When they select a reaction they are assigned a temporary role (24 hours) which will grant them access to the game specific category #tryouts channel they've selected. I've been successful with getting all of the roles assigned using YAG's gui interface. However, I would also like for a message to be sent to the game specific #tryouts channel with an embed (similar to a welcome message) stating that they would like to tryout, to notify the 'team' that they are "in the queue". So the process would look something like this:
User A pops into (Some Community) #general-tryouts -> reads the menu asking them which team they want to tryout for and selects option 1 (':one:') -> User A is given the role for TempGame1 and can now see (Some Game) #tryouts AND simultaneously a message is sent to (Some Game) #tryouts on their behalf.
If they choose option 2 they will receive a TempGame2 role and a message should be sent to (Another Game) #tryouts.
If they choose option 3 they will receive a TempGame3 role and a message should be sent to (ThisOther Game) #tryouts.
YAGPDB has the option with it's custom commands to fire a command triggered by a reaction given in a certain channel by someone with a certain role. The issue is getting the result of which reaction they selected, and that dictating where the message is sent. I'm really not even concerned if it's just a generic message. I just want User A to be able to react at a 'community' level and a message to get passed in to (Some Game) #tryout, (Another Game) #tryouts, or (ThisOther Game) #tryouts based on their selection.
My apologies in advance. I am only proficient enough to code a simple I say "ping" you output "pong" sort of transaction, and got in a little over my head in short order. I have looked at the developer resources trying to piece something together to no avail, as well as pulling a similar snippet of code from here and attempting to modify it to suit my needs, also to no avail. Any help would be greatly appreciated.
Code Sample
if (reaction.message.id === '730000158745559122') {
let channel = reaction.message.guild.channels.cache.get(targetChannelId);
console.log(reaction.emoji)
if (channel) {
let embed = new Discord.MessageEmbed();
embed.setAuthor(
user.tag,
user.displayAvatarURL({
dynamic: true,
format: 'png',
}),
);
embed.setDescription(`${user} has react a: ${reaction.emoji}`);
channel.send(embed);
}
}
Visual Representation
New
in the code if (reaction.message.id === '730000158745559122') the 73000 portion represents that whole message as a focal point on what the bot is 'listening' for. Any reaction to it, be it 1, 2, or 3 will trigger this singular process. So by what you are saying by using the (id === 123 || id === 456 || id === 789) {} would likely be the way to go if I had more than one message is was 'collecting' on for a lack of better way to state it. I believe what I need to do is
`if (reaction(':one:').message.id === 123 {send message ('nifty embed')to channel.id 12345}
if (reaction(':two:').message.id === 123 {send message ('nifty embed') to channel.id 67890}
if (reaction(':three:').message.id === 123 {send message ('nifty embed') to channel.id 16273}`

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

delete bot message after 2 user messages prior

javascript is still vague to my knowledge, and I cannot be precise on the sensibility in the following code I have manufactured. I am programming a discord bot that categorizes messages into a variety of channels, and the question has approached me to how I can program the bot by deleting follow up bot messages after 2 user messages were sent subsequently after the bot message.
if (bot.on(client, user.msg = '2'));{
msg.channel('message' = msg.delete)
}
Help is to be requested and I hope my query makes sense in the context I am implying, Regards, Coder
P.S: How do I change the bot messages text color as well?
No offense, but your code was completely faulty, so I just made some new code.
bot.on('message', aysnc message => {
var messagenumber = 0; //Makes variable for the number of messages sent
if(message.member.user.username === bot.user.username) return; //If the person who posts a message is the bot, it doesn't the code below.
if(messagenumber = 1) return bulkDelete(100), messagenumber = 0 //Checks if the variable is 1, and if it is, this means it's the second time a message posted, so it deletes messages (Limit is 100) then resets variable.
messagenumber = 1; //Makes variable 1 (This is to make it know it is the the second time a message is posted for the next time).
});
I didn't test this code, so it may not work properly, but if it does work I hope it helps you with your bot.
For the P.S (Changing text color): You can use these (Replace "NoKeyWordsHere" with your message). I don't recommend this, cause it'd take a long time to add it to every message sent. (You can use these on your messages too)

Resources