【发布时间】:2022-01-25 19:23:06
【问题描述】:
为什么这个命令不起作用我是编码新手,非常感谢一些帮助我没有收到任何错误我很难自己发现问题。
client.on('messageCreate', message => {
if (message.channel.type != 'text' || message.author.bot)
return;
let command = message.content.split(' ')[0].slice(1);
let args = message.content.replace('.' + command, '').trim();
switch (command) {
case 'ping': {
message.channel.send('Pong! (~ ' + client.ping + 'ms)');
break;
}
case 'uptime': {
// client.uptime is in millseconds
// this is just maths, I won't explain much of it
// % is modulo, AKA the remainder of a division
let days = Math.floor(client.uptime / 86400000);
let hours = Math.floor(client.uptime / 3600000) % 24;
let minutes = Math.floor(client.uptime / 60000) % 60;
let seconds = Math.floor(client.uptime / 1000) % 60;
message.channel.send(`__Uptime:__\n${days}d ${hours}h ${minutes}m ${seconds}s`);
break;
}
}
});
【问题讨论】:
标签: javascript discord.js command bots