消息未转移到其他聊天,但反应在控制台上很重要

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

我想将嵌入的消息转移到另一个带有反应的聊天中,但我遇到了一些麻烦,因为 BOT 没有使用此代码转移消息:

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

当我添加这个是为了不让他做出自己的反应并在聊天中发垃圾邮件时:

    if (message.author.bot) return;

他只是忽略了转消息。

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

猜想问题出在这里:

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

您使用单个“=”运算符所做的是将 analiseChannelID 值分配给 message.guild.channels.id(因为 guild.channels 是渠道管理器,所以它甚至不存在) 然后检查分配的值是否不是 javascript 的 falsy 值。不幸的是,您的问题对于您要实现的目标不是很清楚,但我猜您想要做的是:

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 */ }
});

, 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 对象中所述,它表示做出反应的用户。

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

注意代码中有更多错误

  • if 语句的条件输入不正确。它必须是 =====
  • message.guild.channels.id 未定义。如果你想检查一个频道是否存在,这就是我认为你正在做的,使用 message.guild.channels.cache.has("ID")