user.send both resolving and rejecting

Discord.js v14.13.0 I have the following code (the user is fetched by Client.users.fetch(discordUserId).then()): user.send("reply goes here").then((message) => { console.log(message); }).catch((err) => { console.log(err.message); }).finally(() => { // stuff }); When the code fires, the message is sent as a DM to the user (correct), but I also get a rejection with a "Cannot send message to this user" error. I'm not sure why it's both resolving and rejecting, but that doesn't seem right so I assume I'm missing something. Thoughts? Edit: The error is a DiscordAPIError, code 50007.
9 Replies
d.js toolkit
d.js toolkit16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Danial
Danial16mo ago
Can you show more code, where you're fetching?
Jaede
JaedeOP16mo ago
Sure... const client = new Client({ intents : [ GatewayIntentBits.Guilds, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent ], partials : [ Partials.Channel, Partials.Message ] }); // lots of stuff happens inbetween client.users.fetch(discordUserId).then((user) => { if( user ) { //code block from above } else { // resolve a previous promise } }).catch((err) => { // handle the errors and reject })
Danial
Danial16mo ago
No need for that if statement, if the user doesn't exist, the promise will reject
Jaede
JaedeOP16mo ago
k, good to know i assume that doesn't impact the resolve/reject of the user.send though i get the message in my test user's DMs ...along with the message on the console, and the error in the console from both the .then and .catch blocks
duck
duck16mo ago
where is this code executing? is it in the messageCreate event? could you share more of the code leading up to user.send?
Jaede
JaedeOP16mo ago
yes...effectively: client.on("messageCreate", async(message) => { client.users.fetch... }); there's more stuff in there, but that's the flow
duck
duck16mo ago
so it's executing for the dm your bot sends as well? your bot can't send a dm to itself these would be two separate promises, 1 resolving and 1 rejecting
Jaede
JaedeOP16mo ago
no, i test for if the author of the message is the bot and ignore anything sent by the bot...this is specifically for a test user sending the bot a DM, the bot processing that DM, and sending a reply back
Want results from more Discord servers?
Add your server