-2

I'm trying to make it so when my bot picks up a reaction in a specific channel, it'll see if it hit 10 reactions on a specific reaction. Then it'll delete the reacted message and post it into another specific channel with a message attached to it.

Here's the code

doopliss.on('message', message => {
  if (message.channel.id === "587066921422290953") {
    setTimeout(function(){
      message.react(message.guild.emojis.get('587070377696690177'))
    }, 10)
    setTimeout(function(){
      message.react(message.guild.emojis.get('587071853609353256'))
    }, 50)
    setTimeout(function(){
      message.react(message.guild.emojis.get('587070377704816640'))
    }, 100)
  }
});
const message = require("discord.js");
const emoji = require("discord.js");
const reaction = require("discord.js");
doopliss.on('message', message => {
  if (message.channel.id === "587066921422290953") {
  let limit = 2; // number of thumbsdown reactions you need
  if (message.reaction.emoji.name == message.guild.emojis.get('587070377696690177') 
  && reaction.count >= limit) message.reaction.message.delete();
  let tcontent = message.reaction.message.content
  let accept = message.guild.channels.get('587097086256873483')

  accept.send(`${tcontent} \`\`\`This server suggestion has been accepted by the community! Great job! Now a staff member just needs to forward it to username.\`\`\``)
}})

Can't figure out how to do this.

Expected Result: Bot sees if post has 10 reactions, then delete it and take the same message to a different channel Actual Result: An error occurs Cannot read 'channel' property

SomePerson
  • 1,171
  • 4
  • 16
  • 45

1 Answers1

0

First I want to say that some question here like this one have what you search.

Moreover, the discord documentation and the guide provide an awaiting reactions section.

There is some other question that refer to the subject or the function used in the guide and by searching a bit you can even find question like this one which is almost the same thing as you.

However, here is a complete example of what you want to do. You can add a timer to the promise instead of just waiting. I didn't use the reaction collector because promise are a bit faster, but you can also create a management system of multiple collector , or use the client.on('messageReactionAdd').

const Discord = require('discord.js');
const config = require('./config.json');


const channelSuggestion = '<channelID>';
const channelSend = '<channelID>';
const emojiReact = '<emojiID>';
const prefixSuggestion = '!';
const reactionMax = 11;

const client = new Discord.Client();
client.on('ready', () => {
  console.log('Starting!');
  client.user.setActivity(config.activity);
});

client.on('message', (msg) => {
  if ((msg.content[0] === prefixSuggestion) && (msg.channel.type === 'dm')){
    sendSuggestion(msg);
  }
});


function filter(reaction) {
  return reaction.emoji.id === emojiReact;
}

function moveSuggestion(msg) {
  client.channels.get(channelSend).send(msg.content)
    .then(() => msg.delete()).catch(err => console.log(error));
}

function sendSuggestion(msg){
  client.channels.get(channelSuggestion).send(msg.content.substr(1))
    .then((newMsg) => newMsg.react(emojiReact))
    .then((newMsgReaction) => 
      newMsgReaction.message
      .awaitReactions(filter, {max: reactionMax})//, time: 15000, errors: ['time']})
      .then(collected => {
        moveSuggestion(newMsgReaction.message);
      })
      // .catch(collected => {
      //   console.log(`After a minute, only ${collected.size} out of 10 reacted.`);
      // })
     );
}

client.login(config.token)
  .then(() => console.log("We're in!"))
  .catch((err) => console.log(err));

The bot will listen to dm message (I don't know how you want your bot to send the suggestion message, so I made my own way) which start with a !.
Then the bot will send a message to a specific channel, wait for N person to add a reaction, and then will send the message to another channel.

JackRed
  • 1,188
  • 2
  • 12
  • 28
  • It's gonna be in a text channel, and no prefix is required. It'll just react and if it hits 11 reactions (including the bot), it'll delete the message, copy the content over to the other channel. When I was filling some parts in with the correct variables, `const channelSuggestion = 'id'`, and changing some things to meet my bot's prefix, it didn't work. – SomePerson Jun 09 '19 at 19:32
  • @SomePerson what do you mean it didn't work? Can you give me more details? What did you exactly change? Is there error? – JackRed Jun 09 '19 at 20:02
  • Here's what I did `const channelSuggestion = '587097052324954132'; const channelSend = '587097086256873483'; const emojiReact = '587070377696690177'; const reactionMax = 2;` I changed all the `client` to `doopliss` and changed the `msg.channel.type` to `text` and tried setting the `client.on` to the `doopliss.on('messageReactionAdd'` Then when I sent a message in `channelSuggestion` the emotes popped up, I reacted on all of them, and nothing happened. – SomePerson Jun 09 '19 at 22:29
  • Did you try my example without changing anything? Did you try to log what is happening to understand why it's not working? My example send a message in a channel, react with an emot and wait for N emot on the message It's not intended to work for a reaction as it is If you want to pick any messages instead of a messages sent by the bot, you'll have indeed to use a "messageReactionAdd" but you'll have to modify `sendSuggestion` – JackRed Jun 10 '19 at 06:46
  • I have to change all the `client` to `doopliss` as that's the commando client I'm using. Plus I have to remove portions of the code where it creates the new user and the login. In the code, it renders some of the variables such as the `collected` as declared but never used. I changed the `message` to `messageReactionAdd` – SomePerson Jun 20 '19 at 02:00
  • Do you understand what the answer I gave you do? @SomePerson – JackRed Jun 20 '19 at 06:35
  • Because I can't do everything for you. The code I used works fine and do what I describe. The dm message is just a trigger to set up the reaction/suggestion. If you want to do it with a reaction, you just have to do a messageReactionAdd and if the emot match the one you want you call `sendSuggestion` with the message which got the reaction. And yeah, collected is useless, I used it to log information – JackRed Jun 20 '19 at 07:11