Home > Blockchain >  Message not being tranfered to other chat but the reaction counts on console
Message not being tranfered to other chat but the reaction counts on console

Time:11-03

I would like to transfer an embed message to another chat with reactions, but I'm having some troubles because the BOT isn't tranferying the message with this code:

client.on("messageCreate", message => {
    if (message.channel.id === analiseChannelID) {
        message.react(aprovada);
        message.react(nula);
        message.react(negada);
    } else if (message.channel.id === aprovadasChannelID) {
        message.react(arquivada);
        message.react(negada);
    } else if (message.channel.id === negadasChannelID) {
        message.react(arquivada);
        message.react(negada);
    } else if (message.channel.id === nulaChannelID) {
        message.react(arquivada);
        message.react(negada);
    }
});

client.on("messageReactionAdd", ({ message }) => {
    const analiseChannel = message.client.channels.cache.get(analiseChannelID);
    const aprovadasChannel = message.client.channels.cache.get(aprovadasChannelID);

    console.log("Reaction");

    if (message.author.bot) return;

    if (message.guild.channels.id = analiseChannelID) {
        const { embeds } = message
        aprovadasChannel.send({
            embeds
        })
    }
});

When I added this to not let him take his own reaction and spam the chat:

    if (message.author.bot) return;

he just ignore to transfer the message.

What I have to do is if there is a new embed on analiseChannelID, he should react with 3 emojis, and deppending on those reactions, he would transfer the message to aprovadasChannelID and delete from analiseChannelID

CodePudding user response:

As said in the comments, you sent the message as a Discord webhook. Webhooks are classified as bot messages. If you were trying to get the user who reacted, you can use the second argument of the messageReactionAdd event. It's a User object which represents the user who reacted.

client.on("messageReactionAdd", ({ message }, user) => { //get the User who reacted
    const analiseChannel = message.client.channels.cache.get(analiseChannelID);
    const aprovadasChannel = message.client.channels.cache.get(aprovadasChannelID);

    console.log("Reaction");

    if (user.bot) return;

    if (message.guild.channels.id = analiseChannelID) {
        const { embeds } = message
        aprovadasChannel.send({
            embeds
        })
    }
});

Note there are more mistakes in the code

  • the if statement's condition is not put in correctly. It must be either == or ===
  • message.guild.channels.id is undefined. If you would like to check if a channel exists, which is what I think you are doing, use message.guild.channels.cache.has("ID")

CodePudding user response:

Guess the problem is here:

if (message.guild.channels.id = analiseChannelID)

What you're doing by using the single '=' operator is assigning the analiseChannelID value to message.guild.channels.id(which doesn't even exists since guild.channels is a channel manager) and then checking if the value assigned is not a falsy value for javascript. Unfortunately your question isn't very clear about what you're trying to achieve, but i guess what you want to do instead is something like:

client.on("messageReactionAdd", ({ message }) => {
    if (message.author.bot) return;

    const analiseChannel = message.client.channels.resolve(analiseChannelID);
    const aprovadasChannel = message.client.channels.resolve(aprovadasChannelID);

    // you can use the has method since the cache is a Collection instance
    // this if you want to check if the guild has a channel with that id
    if (message.guild.channels.cache.has(analiseChannelID)) {
        const { embeds } = message;
        aprovadasChannel.send({
            embeds
        });
    }
    // this if you want to ckeck if the channel in which the message has been sent is that channel id
    if(message.channel.id === analiseChannelID) { /* do stuff */ }
});
  • Related