How can I grab bot sent messages in a users dm with the bot if I dont have message intent?
I am making a bot that lets you communicate through it. 1 user can run a command and the other user will get the message in their dms. Same thing the other way around. I want to make it so messages can be reacted on, deleted, ect. For this I can store the message ID in a database and grab it. The issue is I dont know how. How do I grab a message from a users dm by id?
The other option I have is to somehow store the raw message object in my database, the issue is I cant without serializing it or something. Every time I try to deserialize it the bot crashes. I have also tried to manually reconstruct it by passing in a json into a new Message(). I would like some help on solving this. I dont care what way gets it to work, im just trying to get it to work. If there is no way to do it then how would I do is assuming I did get message intent?
10 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Node version: v16.13.1
Discord js version: [email protected]
What would the code look like? and do I need message intent privilege to do this?
Fetch the DMChannel from the client and then fetch the messages from the DMChannel
I understand that, but do I need intent privilege to do this?
I would assume
DIRECT_MESSAGES
How would I do that? since the code I found seems to need intent privileges. Also it seems to be based on the guild. Is there a way to grab a dm channel without knowing what server they are in?
I have been trying
but this gives me
TypeError: Cannot read properties of null (reading 'fetch')
It fails on the second fetch.
user.dmChannel
is nullPretty sure DMChannels aren't cached initially, so unless it's already in cache you have to fetch the channel
I made this. That seems to work. Hopefully this is correct
Now I have a list of message ids, how do I get them in bulk so that I dont spam the api? Thanks!
Just do a fetch on the channel's messages property and it will return up to 100 messages
If you only want messages sent by the bot, use a filter
Alright, thanks! Not sure how to close these forum channels but im good now