为发送的每条消息赚取积分 Bot Discord.js

我的 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,function(err) {
          if (err) console.log(err)
        });
      }
    }
  }
});

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

Thats the console

在这里我必须获得积分,但没有任何反应: Thats the results

我是初学者,谢谢

jscj4567 回答:为发送的每条消息赚取积分 Bot Discord.js

我没有理解这段代码片段中的一行,也没有理解您对 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]不存在的情况你好像没处理好。

,
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",4));

我试过了,还是不行

本文链接:https://www.f2er.com/1063562.html

大家都在问