'DiscordJS v12 args[0].isInteger is not a function
if (!args[0])
return message.channel.send(`<:warning:943421375526355024> | **Please Give Me Amounts Of Messages!**`);
if (isNaN(args[0]))
return message.channel.send(`<:warning:943421375526355024> | **Please Give Me Number Value!**`);
if (!isInteger(args[0]))
return message.channel.send(`<:warning:943421375526355024> | **Please Provide A Whole Number**`);
if (args[0] > 100)
return message.channel.send(
`<:warning:943421375526355024> | **I Can't Delete ${args[0]} Messages Because Of Discord Limit!**`
);
if (args[0] > 0) message.channel.bulkDelete(args[0], true).then(Message => {
return message.channel.send(`<:check:947079937372872704> | **Cleared ${Message.size} messages!**`).then(Message => {
setTimeout(function () {
Message.delete()
.catch()
}, 2000)
}
)
})
}
}
Error:
if (!isInteger(args[0]))
^
ReferenceError: isInteger is not defined
I am trying to stop the bot from crashing when inputting decimal numbers with my purge command.
I have tried this:
if (!isInteger(args[0]))
return message.channel.send(<:warning:943421375526355024> | `**`Please Provide A Whole Number`**`);
but it returns the error above. How would I make it work?
Solution 1:[1]
It should be Number.isInteger(), but it will always return false as args[0] is a string. You can convert it to a number and do those validations:
if (!args[0])
return message.channel.send(
`<:warning:943421375526355024> | **Please Give Me Amounts Of Messages!**`,
);
let amount = Number(args[0]);
if (isNaN(amount))
return message.channel.send(
`<:warning:943421375526355024> | **Please Give Me Number Value!**`,
);
if (!Number.isInteger(amount))
return message.channel.send(
`<:warning:943421375526355024> | **Please Provide A Whole Number**`,
);
if (amount > 100)
return message.channel.send(
`<:warning:943421375526355024> | **I Can't Delete ${amount} Messages Because Of Discord Limit!**`,
);
if (amount > 0)
message.channel.bulkDelete(amount, true).then((Message) => {
return message.channel
.send(
`<:check:947079937372872704> | **Cleared ${Message.size} messages!**`,
)
.then((Message) => {
setTimeout(function () { Message.delete().catch(); }, 2000);
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zsolt Meszaros |
