I want to make a discord help bot, which take questions to users. If the users can answer all questions correct, the bot give them a role on the server.
How could I do that, the bot give role to user on the server?
I wrote in javascript, with discord.js module.
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.");
}
}