Javascript 提及后回复信息

Javascript 提及后回复信息,javascript,discord.js,Javascript,Discord.js,我想为Discord bot编写一个游戏,但我对该代码有一个小问题: (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 e

我想为Discord bot编写一个游戏,但我对该代码有一个小问题:

(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('❎');
    }
  }
})();
(异步函数(){
如果(命令==“rps”){
message.channel.send(“**请提及您想与之一起玩的用户。**”;
var member=message.indications.members.first()
如果(!成员)返回{
const embed=new Discord.RichEmbed()
.setColor(0xffffff)
.setFooter('请在DMs中查找')
.setDescription(args.join(“”))
.setTitle(`**您接受****的游戏吗?**`);
let msg=wait message.channel.send(嵌入);
等待消息。反应('✅');
等待消息。反应('❎');
}
}
})();
我想在提到会员后回复留言。如下:
用户:
rps

Bot:
请提及用户

用户:
提及用户

Bot:
嵌入

您可以使用:

(异步函数(){
如果(命令==“rps”){
message.channel.send(“**请提及您想与之一起玩的用户。**”;
let filter=msg=>{
如果(msg.author.id!=message.author.id)返回false;//消息必须来自原始作者
如果(msg.indivations.members.size==0){//它至少需要一次提及
msg.reply(“您的消息没有提及。”);
返回false;
}
返回msg.indications.members.first().id!=msg.author.id;//提及的内容不应是作者本身
};
let collected=await message.channel.await messages(过滤器{
最大匹配:1,
时间:60000
});
//如果没有匹配项(即他们没有回复)
if(collected.size==0)返回message.edit(“命令已取消”);
//否则,请获取成员
让member=collected.first().notices.members.first();
const embed=new Discord.RichEmbed()
.setColor(0xffffff)
.setFooter('请在DMs中查找')
.setDescription(args.join(“”))
.setTitle(`**您接受****的游戏吗?**`);
让msg=wait message.channel.send({
嵌入
});
等待消息。反应('✅');
等待消息。反应('❎');
}
})();

您的代码中到底有什么不起作用,控制台中有什么错误?在if语句之后返回并创建一个新的作用域..这是有意的吗?有什么问题吗?什么不起作用?您到底想发生什么?谢谢
(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('❎');
  }
})();