2
votes

I am currently writing an application system in my Discord bot.

The system looks like this:

You react to a message and get a message via DM then he asks about 5 questions (1 question, the user writes the answer, then the next one follows etc.) At the end there should be a message "Thank you for your application". Then the bot should send the answers in a channel on my Discord but sorted according to the questions.

What is your name (question 1):

I'm blah blah blah

How old are you (question 2):

Second Answer

...

after that there should be a react system, that is, you press a reaction, the bot gives the applicant the role and delete the message, but that comes afterwards.

Now to the problemL I manage to react to the message, and the person gets the DM, but how do you write the questions in an embed message and then send them in a channel as described above?

This is the current code:

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)
 
     

  });








        }     
    }
);
1
Please show the code you currently have. - Daemon Beast
I add the current Code ;D - Heptix

1 Answers

0
votes

You should take a look at MessageCollector event in Discord.js. This article might be helpful for you.

Don't be confused with ReactionCollector and emojis reaction it's very different things

After that you should store user's data (answers) somehow, in your DB for example.

Also, to send a embedded message with answers you should know the exact ID of your channel, or request it from Discord server/guild by systemChannelID.

Also, your bot should been able (have a permission) to send messages in this channel.

The example of sending a message for Discord ~v11:

//inside async/await function
    let embed = new MessageEmbed();
    embed.setTitle("Test")
    await message.channel.send(embed );

Usefull embeded generators can be found here or here