'Build an application system with reactions [Discord.js v12.5]
I want to build an application system on discord and I want to use reactions to accept or decline the applications. The thing is, that there is this parameter 'reactuser' which is actually the user who reacts to the start application button. So that's my target, but when I react to the 'accept/decline' button the 'reactuser' parameter changes to my id and it sends the message to me instead of the applicant. I can't figure out how to fix this, are there any ideas?
client.on("messageReactionAdd", async (reaction, user) => {
const { message } = reaction;
if(user.bot || !message.guild) return;
if(message.partial) await message.fetch();
if(reaction.partial) await reaction.fetch();
let reactuser = user
if(message.guild.id === "762033023319277668" && message.channel.id === config.apply_channel_id && message.id === '942842387032596550' && (reaction.emoji.name === "📥" || reaction.emoji.id === "")){
let guild = await message.guild.fetch();
let channel_tosend = guild.channels.cache.get(config.finished_applies_channel_id);
if(!channel_tosend) return console.log("RETURN FROM !CHANNEL_TOSEND");
const answers = [];
let counter = 0;
reaction.users.remove(reactuser)
ask_question(config.QUESTIONS[counter]);
function ask_question(qu){
if(counter === config.QUESTIONS.length) return send_finished();
reactuser.send(qu).then(msg => {
msg.channel.awaitMessages(m=>m.author.id === reactuser.id, {max: 1, time: 60000, errors: ["time"]}).then(collected => {
answers.push(collected.first().content);
ask_question(config.QUESTIONS[++counter]);
}).catch(error => {
reactuser.send(`**You are either out of time or something went wrong with the bot!**`)
})
}).catch(error => {
message.channel.send(`**Something went wrong while I tried to send you a DM**`)
})
}
function send_finished(){
let embed = new Discord.MessageEmbed()
.setColor("#CD8BF2")
.setTitle("💻A new Discord Helper application from: " + reactuser.tag)
.setDescription(`${reactuser}`)
.setFooter(reactuser.tag, reactuser.displayAvatarURL({dynamic:true}))
.setTimestamp()
for(let i = 0; i < config.QUESTIONS.length; i++){
try{
embed.addField(config.QUESTIONS[i], '```' + String(answers[i]).substr(0, 1024) + '```')
}catch{
}
}
channel_tosend.send(embed).then(embedMessage => {
embedMessage.react("✅");
embedMessage.react("❌");
})
reactuser.send("Thanks for applying to: " + message.guild.name)
}
}
if(reaction.emoji.name === '✅') {
if(!reaction.message.channel.name.includes("📨application-data"))return;
reactuser.send("🎉Yay! Your application got accepted on: "+"`"+message.guild.name+"`"+"\nhttps://tenor.com/view/congrats-the-office-happy-yay-celebration-gif-4115606")
}
/* if(reaction.emoji.name === '✅') { if(!reaction.message.channel.name.includes("📨application-data"))return;
User.send("🎉Yay! Your application got accepted on: "+"`"+message.guild.name+"`"+"\nhttps://tenor.com/view/congrats-the-office-happy-yay-celebration-gif-4115606")
} */
if(reaction.emoji.name === '❌') {
if(!reaction.message.channel.name.includes("📨application-data"))return;
let data = await sa.findOne({MsgID:reaction.message.id})
if(!data) return;
let User = message.mentions.users.first()
if(!User) return message.channel.send("Please provide a user for me to decline")
User.send("❗Your application was declined on: "+"`"+message.guild.name+"`" + "\nhttps://tenor.com/view/the-office-crying-michael-scott-sad-upset-gif-9816214")
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
