提及后返回消息

时间:2018-11-07 22:26:14

标签: javascript discord.js

我想为Discord机器人编写游戏代码,但该代码有一些问题:

(async function() {
  if (command == "rps") {
    message.channel.send("**Please mention a user you want to play with.**");

    var member = message.mentions.members.first()
    if (!member) return; {
      const embed = new Discord.RichEmbed()
        .setColor(0xffffff)
        .setFooter('Please look in DMs')
        .setDescription(args.join(' '))
        .setTitle(`<@> **Do you accept** <@>**'s game?**`);
      let msg = await message.channel.send(embed);
      await msg.react('✅');
      await msg.react('❎');
    }
  }
})();

我想让EmbedMessage在提及成员后返回。像这样:
使用者:rps
机器人:Please mention a user
使用者:mention user
机器人:embed

1 个答案:

答案 0 :(得分:1)

您可以使用TextChannel.awaitMessages()

(async function() {
  if (command == "rps") {
    message.channel.send("**Please mention a user you want to play with.**");

    let filter = msg => {
      if (msg.author.id != message.author.id) return false; // the message has to be from the original author
      if (msg.mentions.members.size == 0) { // it needs at least a mention
        msg.reply("Your message has no mentions.");
        return false;
      }
      return msg.mentions.members.first().id != msg.author.id; // the mention should not be the author itself
    };
    let collected = await message.channel.awaitMessages(filter, {
      maxMatches: 1,
      time: 60000
    });

    // if there are no matches (aka they didn't reply)
    if (collected.size == 0) return message.edit("Command canceled.");
    // otherwise get the member
    let member = collected.first().mentions.members.first();

    const embed = new Discord.RichEmbed()
      .setColor(0xffffff)
      .setFooter('Please look in DMs')
      .setDescription(args.join(' '))
      .setTitle(`<@> **Do you accept** <@>**'s game?**`);
    let msg = await message.channel.send({
      embed
    });
    await msg.react('✅');
    await msg.react('❎');
  }
})();