如何计算命令被使用的次数 [discord.js]
how to count how many times a command is used [discord.js]
只是当人们使用教程 !ping 命令时,我想计算多少次并在聊天中显示出来。像 'ping has been used this many times' 我发现了一些关于 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!!!`);
},
};
您尝试做的事情的正确解决方案很简单。就这样做吧。
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。
只是当人们使用教程 !ping 命令时,我想计算多少次并在聊天中显示出来。像 'ping has been used this many times' 我发现了一些关于 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!!!`);
},
};
您尝试做的事情的正确解决方案很简单。就这样做吧。
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。