【问题标题】:Discord.js Reaction issueDiscord.js 反应问题
【发布时间】:2021-01-28 01:29:53
【问题描述】:

当我对频道“idere”中的一条消息做出反应时 ????然后它将消息发送到“idere-accepted”,当我对 ???? 做出反应时然后它将消息发送到“idere-declined”,这就是我所做的

但是当我已经准备好对一条消息做出反应并想要对另一条以“idere”发送的消息做出反应时,问题就出来了????然后它在“idere-accepted”中发送消息 2 次,当我第三次做出反应时,它发送消息 3 次问题是一样的????

const emojiChannelName = "idere";
const emojiChannelNameAccepted = "idere-accepted";
const emojiChannelNameDeclined = "idere-declined";

client.on("message", async (message) => {
  if (message.guild.id === guildID) {
    if (message.channel.name === emojiChannelName) {
      if (message.author.id !== botID) {
        await message.react("????");
        await message.react("????");
      }
    }
    client.on("messageReactionAdd", async (reaction, user) => {
      if (reaction.message.partial) await reaction.message.fetch();
      if (reaction.partial) await reaction.fetch();

      let channelAccept = message.guild.channels.cache.find(
        (channel) => channel.name === emojiChannelNameAccepted
      );

      let channelDeclined = message.guild.channels.cache.find(
        (channel) => channel.name === emojiChannelNameDeclined
      );

      if (user.bot) return;
      if (!reaction.message.guild) return;

      if (reaction.message.channel.name === emojiChannelName) {
        if (reaction.emoji.name === "????") {
          if (user.id === config.owner) {
            if(message.author.id !== botID) {
              let accept = new Discord.MessageEmbed()
              .setColor("GREEN")
              .setTitle("Ide accepted")
              .setDescription(
                `${message.author} Havde en ide som er\n**${reaction.message.content}**\n(Testing)`
              )
              .setTimestamp()
              .setFooter(`Accepted af ${user.username}`);
              await channelAccept.send(accept);
              reaction.message.delete();
            }
          } else {
            reaction.message.reactions
              .resolve("????")
              .users.remove(reaction.users.cache.keyArray()[1]);
          }
        }
        if (reaction.emoji.name === "????") {
          if (user.id === config.owner) {
            let declined = new Discord.MessageEmbed()
              .setColor("RED")
              .setTitle("Ide declined")
              .setDescription(
                `${message.author} Havde en ide som er\n**${reaction.message.content}**\n(Testing)`
              )
              .setTimestamp()
              .setFooter(`Declined af ${user.username}`);
              await channelDeclined.send(declined);
              reaction.message.delete();
          } else {
            reaction.message.reactions
              .resolve("????")
              .users.remove(reaction.users.cache.keyArray()[1]);
          }
        }
      }
    });
  }
});```

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    在您发送消息的地方,您可以尝试返回消息。

    试试这个:

    const emojiChannelName = "idere";
    const emojiChannelNameAccepted = "idere-accepted";
    const emojiChannelNameDeclined = "idere-declined";
    
    client.on("message", async (message) => {
      if (message.guild.id === guildID) {
        if (message.channel.name === emojiChannelName) {
          if (message.author.id !== botID) {
            await message.react("?");
            await message.react("?");
          }
        }
        client.on("messageReactionAdd", async (reaction, user) => {
          if (reaction.message.partial) await reaction.message.fetch();
          if (reaction.partial) await reaction.fetch();
    
          let channelAccept = message.guild.channels.cache.find(
            (channel) => channel.name === emojiChannelNameAccepted
          );
    
          let channelDeclined = message.guild.channels.cache.find(
            (channel) => channel.name === emojiChannelNameDeclined
          );
    
          if (user.bot) return;
          if (!reaction.message.guild) return;
    
          if (reaction.message.channel.name === emojiChannelName) {
            if (reaction.emoji.name === "?") {
              if (user.id === config.owner) {
                if(message.author.id !== botID) {
                  let accept = new Discord.MessageEmbed()
                  .setColor("GREEN")
                  .setTitle("Ide accepted")
                  .setDescription(
                    `${message.author} Havde en ide som er\n**${reaction.message.content}**\n(Testing)`
                  )
                  .setTimestamp()
                  .setFooter(`Accepted af ${user.username}`);
                  await channelAccept.send(accept);
                  return reaction.message.delete(); //returns the message delete
                }
              } else {
                reaction.message.reactions
                  .resolve("?")
                  .users.remove(reaction.users.cache.keyArray()[1]);
              }
            }
            if (reaction.emoji.name === "?") {
              if (user.id === config.owner) {
                let declined = new Discord.MessageEmbed()
                  .setColor("RED")
                  .setTitle("Ide declined")
                  .setDescription(
                    `${message.author} Havde en ide som er\n**${reaction.message.content}**\n(Testing)`
                  )
                  .setTimestamp()
                  .setFooter(`Declined af ${user.username}`);
                  await channelDeclined.send(declined);
                  return reaction.message.delete(); //returns the message delete
              } else {
                reaction.message.reactions
                  .resolve("?")
                  .users.remove(reaction.users.cache.keyArray()[1]);
              }
            }
          }
        });
      }
    });
    

    【讨论】:

    • 您的代码仍然存在问题,但请尝试
    猜你喜欢
    • 2020-11-30
    • 2020-11-30
    • 2021-01-07
    • 2021-06-21
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 2020-11-08
    • 2021-02-07
    相关资源
    最近更新 更多