DM User based on the Username
Hi! I'm trying to use the discord rest API (https://discord.com/developers/docs/resources/user#get-user), but I can't seem to find anything that allows you to DM a user based on their username. This is my current work around so far but it's not working.
First, it says that the discordId variable is not defined after I return it. Second, it says that the variable Discord is not defined. How do I fix this?
6 Replies
- 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 staffnode 18.16.1
"@discordjs/rest": "^2.0.1",
there is no means of fetching or dming a user based on username
you can search for a guild member by username with
<Guild>.members.search()
or the query
option of <Guild>.members.fetch()
, but it would definitely be easier and require fewer api calls if you just used user idsyeah i dont have access to the user's id, only their username
doing this also returns "undefined" for discordId
currently im doing a two step process of getting their discord id from their username
and then dming the id
oh right this is frontend and you're not actually using the main lib
1. you're free to use the
REST
client to handle member fetching
2. you'll want to reference the discord docs directly to see what the /search
endpoint responds with as it's not just a single member object
3. you'll probably also want to ask further questions in ddevs as this is more of a general api topic than how to use @discordjs/rest
#useful-servers
though I'm still not really sure why you couldn't just store user ids rather than usernamesit doesn't make sens ein the context of the project
ill ask in the dev server, thanks!