0

What I would like to eliminate in this code is that the program only reacts to numbers, not other characters, then it says "Not an appropriate value" Can anyone help me with this?

e.g:

  • User: -clearr
  • Bot: How many messages do you want to delete?
  • User: asd
  • Bot: asd message successfully deleted!

This code:

module.exports = {
    name: 'clearr',
    description: "Clear messages!",
    async execute(client, message, args) {
        if(!args[0]) {
            let filter = m => m.author.id === '365113443898097666'
            message.channel.send(`How many messages do you want to delete?`).then(() => {
                message.channel.awaitMessages(filter, {
                    max: 1,
                    time: 10000,
                    errors: ['time']
                })
                .then(message => {
                    message = message.first()
                    message.channel.bulkDelete(message);
                    message.channel.send (`\`${message} message\` successfully deleted!`)
                    .then(message => {
                        message.delete({ timeout: 5000 })
                    })
                    .catch(console.error);
                })
            })
        }
    }
}

Thank you very much in advance for your replies!

1 Answers1

2

You have to use Number.isNaN(+var):

if(Number.isNaN(+args[0])) return message.reply('Please, specify how many messages do you want to delete!')
MegaMix_Craft
  • 2,199
  • 3
  • 10
  • 36
  • `isNaN()` is static and can be invoked without referencing the Number class. Still valid though – Elitezen Oct 31 '21 at 21:45
  • @Elitezen I have no idea why it's not working without `+` sadly, but this is how I use it – MegaMix_Craft Oct 31 '21 at 21:47
  • 1
    I did some research about `+var` and turns out `+` casts the string as a number: https://stackoverflow.com/questions/63906197/what-is-this-syntax-isnanstr – Elitezen Oct 31 '21 at 22:04
  • Thank you very much in advance for your replies! –  Nov 02 '21 at 20:01