-1

我的 Discord 机器人需要帮助,我正在使用 discord.js

所以我做了这个:

client.on("message", async(message) => {
  if (!message.guild) return;
  if (message.author.bot) return;
  if (mentionn) {

    const randomAmountOfCredits = Math.floor(Math.random() * 29) + 1; // Min 1, Max 30
    (message.author.id, message.guild.id, randomAmountOfCredits);
    if (collected.first().content === number) {
      m.delete();
      collected.first().delete();
      credits[mentionn.id].credits += (+randomAmountOfCredits);
      fs.writeFile(path, JSON.stringify(credits, null, 5), function(err) {
        if (err) console.log(err)
      });

      if (collected.first().content !== number) {
        return m.delete();
      } else if (!mentionn) {
        credits[author].credits += (+randomAmountOfCredits);
        fs.writeFile(path, JSON.stringify(credits, null, 5), function(err) {
          if (err) console.log(err)
        });
      }
    }
  }
});

这就像通过发送的每条消息获得积分,但我没有获得任何积分,控制台上没有错误:

那是控制台

在这里我必须获得学分,但什么也没发生: 这就是结果

我是初学者,谢谢

4

2 回答 2

0
client.on("message", async msg => {
// First, generate a random number
const newXP = Math.ceiling(Math.random() * 30);
// Read the existing XPs
const file = fs.readFileSync("credits.json");
// Add some XP to the author of the message
credits[author].credits += -newXP;
    credits[mention.id].credits += +newXP;
  fs.writeFileSync("xp.json", JSON.stringify(file, null, 4));

我已经尝试过了,但仍然无法正常工作

于 2021-02-15T22:33:53.473 回答
0

我不明白这段代码片段的一行,我不明白你对 Pascal Stockert 问题的回答,我也不明白collected(来自收集器?)var 在这里做什么。但我会尽力而为。这就是我添加此功能的方式,随意使用此代码并添加任意数量的条件。

client.on("message", async msg => {
    // First, generate a random number
    const newXP = Math.ceiling(Math.random() * 30);
    // Read the existing XPs
    const file = fs.readFileSync("xp.json");
    // Add some XP to the author of the message
    file[msg.author.id].credits += newXP;
    // Write new XP file
    fs.writeFileSync("xp.json", JSON.stringify(file, null, 4));
    // Done.
});

我没有添加它,但要小心,看起来你不处理file[msg.author.id]不存在的情况。

于 2021-01-24T10:25:35.697 回答