【发布时间】:2020-11-06 07:24:54
【问题描述】:
我目前正在我的 Discord 机器人中编写应用系统。
系统如下所示:
您对一条消息做出反应并通过 DM 收到一条消息,然后他问了大约 5 个问题(1 个问题,用户写下答案,然后下一个问题跟随等)最后应该有一条消息“谢谢你的申请”。然后机器人应该在我的 Discord 频道中发送答案,但会根据问题进行排序。
What is your name (question 1):
I'm blah blah blah
How old are you (question 2):
Second Answer
...
之后应该有一个react系统,就是你按下一个reaction,bot给申请者角色并删除消息,但那是之后的。
现在问题我设法对消息做出反应,并且该人收到了 DM,但是您如何将问题写在嵌入消息中,然后如上所述在频道中发送?
这是当前代码:
bot.on("messageReactionAdd", async (reaction, user) => {
let message = reaction.message,
emoji = reaction.emoji;
if (emoji.name == "????") {
if (reaction.message.partial) await reaction.message.fetch();
if (user === bot.user) return;
reaction.users.remove(user);
user.send("Welcome to your Application")
const questions = [
"What is your name?",
"How old are you?",
"Question 3?",
"Question 4?"
];
const applying = [];
bot.on("message", async message => {
if (message.author.bot) return;
if (applying.includes(message.author.id)) return;
try {
console.log(`${message.author.tag} began applying.`);
applying.push(message.author.id);
await message.channel.send(":pencil: **Application started!** Type `#cancel` to exit.");
for (let i = 0, cancel = false; i < questions.length && cancel === false; i++) {
await message.channel.send(questions[i]);
await message.channel.awaitMessages(m => m.author.id === message.author.id, { max: 1, time: 300000, errors: ["time"] })
.then(async collected => {
application[questions[i]] = collected.first().content
if (collected.first().content.toLowerCase() === "#cancel") {
await message.channel.send(":x: **Application cancelled.**");
applying.splice(applying.indexOf(message.author.id), 1);
cancel = true;
console.log(`${message.author.tag} cancelled their application.`);
}
}).catch(async() => {
await message.channel.send(":hourglass: **Application timed out.**");
applying.splice(applying.indexOf(message.author.id), 1);
cancel = true;
console.log(`${message.author.tag} let their application time out.`);
});
}
await message.channel.send(":thumbsup: **You're all done!**")
await console.log(`${message.author.tag} finished applying.`);
} catch(err) {
console.error(err);
}
let embed = new Discord.MessageEmbed()
.setColor('#1D1D1D')
.setAuthor('New Application',)
.addField("What is your name?", `${}`)
.addField("How old are you?", `${}`)
.addField("Question 3", `${}`)
.addField("Question 4", `${}`)
.addField("Datum:", message.createdAt.toLocaleString())
let sChannel1 = message.guild.channels.cache.get("721515009871577089")
sChannel1.send(embed)
});
}
}
);
【问题讨论】:
-
请出示您目前拥有的代码。
-
我添加当前代码 ;D
标签: node.js discord discord.js