I'm fairly new to discord bots coding and I would like to check if a variable is a number. My code looks like this, I've tried many options for the "if" statement.
const { DiscordAPIError } = require('discord.js');
const Discord = require('discord.js');
module.exports = {
name: 'givecookies',
description: 'Gives cookies to the mentioned user',
execute(message, args) {
let User = message.guild.member(message.mentions.members.first());
if (!User) return message.channel.send('Invalid User');
var cookiesAmount = args.join(' ').slice(22);
if (!cookiesAmount) {
message.reply('invalid amount of cookies');
}
if (typeof `${cookiesAmount}` === 'number') {
console.log('Amount of cookies is a number');
console.log(`USER = ${User}`);
console.log(`Amount of cookies = ${cookiesAmount}`);
var UserID = User.id;
console.log(`USER ID = ${UserID}`);
} else {
message.reply('invalid amount of cookies');
console.log('Amount of cookies is not a number');
console.log(`USER = ${User}`);
console.log(`Amount of cookies = ${cookiesAmount}`);
var UserID = User.id;
console.log(`USER ID = ${UserID}`);
}
},
};
I've also tried if (typeof(cookiesAmount) === 'number')
and if (typeof cookiesAmount === 'number')
, but none of them worked. Regardless what the value is, it acts like if it wasn't a number. I made it to log the value of cookiesAmount and it is always right, it logs '5', but it acts like if it wasn't a number. Any ideas of how to fix this? Thanks.
I'm using discord.js version 12