我想为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
最佳答案
您可以使用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('❎');
}
})();