#Explanation about User.send() callback?

8 messages · Page 1 of 1 (latest)

fallen breach

I have the following snippet:

await member
    .send({
    content: `You have been kicked from: **${interaction.guild.name}**\nReason: **${reason}**`,
    })
    .catch(console.log("User has blocked DMs."));

and it runs both the send and the catch below it. The following snippet:

await member
    .send({
    content: `You have been kicked from: **${interaction.guild.name}**\nReason: **${reason}**`,
    })
    .catch(() => console.log("User has blocked DMs."));

is only slightly different and instead works.
I am curious as to why that is.

patent frigate

because the first one isn't a callback

damn, we don't have a tag for callbacks

fallen breach

I'm aware but there's a case of Role.setPermissions() where this works

patent frigate

no, there isn't.

fallen breach

I'm just buggin then

patent frigate

console.log(...) is not a callback, it's a direct function call
() => ... is an arrow function, a valid callback
callbacks need to be functions to work properly, otherwise the thing you're trying to use as a callback is just executed immediately to be passed to the function

fallen breach

right I see