Why is this command not working I am new to coding and would really appreciate some help I am simply trying to get a bot response time ping command to work this is not producing any errors anymore but it doesn't work either and as I am not getting any errors I am having difficulty discovering the problem on my own.
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;
}
}
});
The issue is that you're checking if GuildChannel#type is text, which is not a valid ChannelType.
Instead, try using GUILD_TEXT.
client.on('messageCreate', message => {
if (message.channel.type !== 'GUILD_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;
}
}
});
Note: In April of 2022 access to message content will become a Privileged Intent. I really recommend you to switch to Slash Commands.
Read more here: Message Content: Privileged Intent for Verified Bots