#Can't send message to user using client.users.fetch

18 messages · Page 1 of 1 (latest)

ocean grove
#

Hey there! I was trying to send a message to a user using their ID but I am getting an error, I am using VS Code and Discord.js v14.7.0

Code:

client.users.fetch(reportObj.reporter).then(user => {user.send("Hey there! I am reaching out on behalf of the Armed Disease Control report team. Thank you for filing your report! One of our staff members has dismissed the report")})```
**reportObj.reporter** is a string containing an ID, for development it has been my ID.
Error:

DiscordAPIError[50035]: Invalid Form Body
user_id[NUMBER_TYPE_COERCE]: Value "null" is not snowflake.
at SequentialHandler.runRequest (C:\Users\24gav\Downloads\ADC\Bot1\node_modules@discordjs\rest\dist\index.js:667:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\Users\24gav\Downloads\ADC\Bot1\node_modules@discordjs\rest\dist\index.js:464:14)
at async REST.request (C:\Users\24gav\Downloads\ADC\Bot1\node_modules@discordjs\rest\dist\index.js:910:22)
at async UserManager.fetch (C:\Users\24gav\Downloads\ADC\Bot1\node_modules\discord.js\src\managers\UserManager.js:91:18) {
requestBody: { files: undefined, json: undefined },
rawError: {
code: 50035,
errors: {
user_id: {
_errors: [
{
code: 'NUMBER_TYPE_COERCE',
message: 'Value "null" is not snowflake.'
}
]
}
},
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'GET',
url: 'https://discord.com/api/v10/users/null'
}

Node.js v17.4.0```

past nexus
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

ocean grove
#

Apologies, I left out a part of the error
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
This was at the top

torn crag
#

reportObj.reporter appears to be null

ocean grove
#

Hmm, I'll look into it. I'm going to feel a little silly if thats the problem.

#

That does not seem to be the problem

#

I added this line of code

#

the console.log

#

And it printed the ID before erroring again

#

Should the ID be a string or an int? @torn crag

torn crag
#

string

ocean grove
#

Okay

torn crag
#

The error is saying that user.fetch was passed null

ocean grove
#

Yes, I understand but it seems the issue was it was trying to use an integer as a string. It is working now after a few .toSting()'s

#

Thanks for the help

torn crag
#

Uhh, you can't really convert and int of that size back into a string in JS ever