Discord.js / Mongodb获取消息作者标签

时间:2020-08-19 04:11:26

标签: node.js mongodb discord.js

此刻,我正尝试记录使用mongodb发送消息的用户标签,但我似乎无法全力以赴获取标签本身:

await client.on('message', id => {

    Config.findOne({
        Author_Tag: id
    }, (err, guild) => {
        if (err) console.error(err);

        if (!guild) {
            const newConfig = new Config({
                Author_Tag: id,
            });

            return newConfig.save()
        }
        })
    }

我意识到message.author.id是必需的,但我不知道它会去哪里。

现在,当有人执行命令时,数据库会记录机器人和用户的消息,而不是标签

1 个答案:

答案 0 :(得分:0)

我知道了:

await client.on("message", (message) => {
  Config.findOne(
    {
      Author_Tag: message.author.tag,
    },
    (err, guild) => {
      if (err) console.error(err);

      if (!guild) {
        const newConfig = new Config({
          Author_Tag: message.author.tag,
        });

        return newConfig.save();
      }
    }
  );
});

我将id更改为message.author.tag