Will
Will

Reputation: 81

.catch running every time even if it is successful

Why is this code running catch every single time? The ban works, the messages get sent and it logs to audit log perfectly fine yet the message always catches, Can someone help me with why this could happen

getBan.ban({reason: banReason})
.then(() => {
    message.channel.send(banEmbed)
    getBan.send(banDM)
})
.catch(message.reply('Something went wrong. Is the user ID valid?'))

it still sends the error message, saying that the getBan is not a function (because the user id/tag is invalid or isnt in the server)

Upvotes: 1

Views: 648

Answers (1)

Zsolt Meszaros
Zsolt Meszaros

Reputation: 23161

It's because catch accepts a function that is called when the promise is rejected. You are invoking the function and setting its result as this function. Try not to call message.reply('Something went wrong. Is the user ID valid?') immediately and pass a function instead as an argument:

.catch(() => message.reply('Something went wrong. Is the user ID valid?'))

Upvotes: 1

Related Questions