【问题标题】:how to count how many times a command is used [discord.js]如何计算命令的使用次数 [discord.js]
【发布时间】:2021-04-01 14:00:15
【问题描述】:

当人们使用教程 !ping 命令时,我想计算多少次并在聊天中显示。就像“ping 已经被使用过很多次”一样,我发现了一些关于 quick.db 的内容,但仍然不太了解。目前,消息显示为 [This has been used This NaN times!!!]

module.exports = {
  name: 'ping',
  description: 'Ping!',
  execute (message, args, ) {
    const db = require('quick.db')
    var times = []
    db.set('times', {hello: 'hi'})
    db.add('times.used', 1)
      let timesused = times.used + 1;
      message.reply('pong');
      message.channel.send(`This has been used This ${timesused} times!!!`);
  },
};

【问题讨论】:

    标签: discord discord.js quick.db


    【解决方案1】:

    您想要做的事情的正确解决方案很简单。就这样做吧。

    const db = require('quick.db');
    
    module.exports = {
      name: 'ping',
      description: 'Ping!',
      execute (message, args) {
        db.add('times.ping', 1); // Adding an amount of one to the countor for the ping command
    
        const timesUsed = db.get('times.ping'); // Getting the amount of uses 
    
        message.reply('pong!');
        message.channel.send('This command has been used '+timesUsed+' times!');
      },
    };
    

    如需更好的解释,请阅读 Quick.db 的 Documentation

    【讨论】:

    • 如果您有任何问题,请告诉我^-^!顺便说一句,如果您可以将我的答案标记为解决方案,那就太酷了。
    • 我还有一件事有问题,是他们的私人信息问题还是我需要做另一个 Stack Overflow 问题
    • 栈溢出没有私信。你必须做另一个问题
    猜你喜欢
    • 2020-07-28
    • 2019-11-28
    • 2011-08-22
    • 2016-10-16
    • 2014-06-24
    • 2014-07-06
    • 2021-05-22
    • 1970-01-01
    • 2020-06-29
    相关资源
    最近更新 更多