【发布时间】:2020-01-07 14:04:07
【问题描述】:
我想制作一个不和谐的帮助机器人,它可以向用户提问。如果用户可以正确回答所有问题,机器人就会在服务器上为他们提供一个角色。
我怎么能这样做,机器人将角色赋予服务器上的用户?
我用 javascript 编写,带有 discord.js 模块。
client.on("message", (datas) => {
if (datas.author.bot) { return; }
let messageArray = datas.content.split(" ");
let command = messageArray[0];
let args = messageArray.slice(1);
if (datas.channel.type === "dm") {
[...]
if (usersInTest[datas.user] !== undefined) {
[...]
} else if (usersInTest[datas.user][0] < testQuestions.length) {
if (Number(datas.content) && Number(datas.content)>=1 && Number(datas.content)<=3) {
if (testQuestions[usersInTest[datas.user][0]][4] === Number(datas.content)) {
if (usersInTest[datas.user][0]+1 >= testQuestions.length) {
datas.channel.send("You successfully complete the test!");
//give role to user
[...]
return;
}
[...]
} else {
[...]
}
} else {
[...]
}
}
}
}
});
function sendQuestion(channel, user) {
if (usersInTest[user] !== undefined || channel !== undefined) {
channel.send(testQuestions[usersInTest[user][0]][0]+"\n\n(1) " + testQuestions[usersInTest[user][0]][1] + "\n(2) " + testQuestions[usersInTest[user][0]][2] + "\n(3) " + testQuestions[usersInTest[user][0]][3] + "\n Type the answer to continue.");
}
}
【问题讨论】:
标签: discord.js