【问题标题】:Discord.js Applying System?Discord.js 应用系统?
【发布时间】: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


【解决方案1】:

您应该查看 Discord.js 中的 MessageCollector 事件。 This article 可能对你有帮助。

不要混淆 ReactionCollector 和表情符号的反应,这是非常不同的事情

之后,您应该以某种方式存储用户的数据(答案),例如在您的数据库中

此外,要发送带有答案的嵌入式消息,您应该知道您频道的确切 ID,或者通过 systemChannelID 从 Discord 服务器/公会请求它。

此外,您的机器人应该能够(拥有权限)在此频道中发送消息。

Discord ~v11 发送消息示例:

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

可以在herehere 找到有用的嵌入式生成器

【讨论】:

  • 谢谢,我稍后试试!
猜你喜欢
  • 2019-04-30
  • 2020-12-17
  • 2021-05-24
  • 2019-10-13
  • 2018-03-26
  • 2021-12-01
  • 2020-11-24
  • 2021-08-23
  • 2021-08-13
相关资源
最近更新 更多