Reputation: 81
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
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