I wanna fetch messages in a dm, like i can in a channel
So i have tried
<user>.messages.fetch(id)
But no luck
So what can i do to fetch messages in a dm
Full code
let id = args[0]
let react = args.slice(1).join(' ')
let fetched = message.author.messages.fetch(id)
fetched.react(react)
I tried fetching a channel from the id of the author But also no luck
CodePudding user response:
You can use message.author.dmChannel
to get a DMChannel
object of the particular user's DMs. Then, you can use .messages.fetch()
to fetch all the messages in the channel, .messages.cache.get()
to fetch a message based on its ID or .messages.cache.find()
to fetch a message based on any property such as its content. An example:
const dmChannel = message.author.dmChannel
const messages = dmChannel.messages.fetch() // This gives you a list of all the message in the channel
const message = dmChannel.messages.cache.get('message-id') // This fetches the message with the particular message id given
const message = dmChannel.messages.cache.find('message-content') // This fetches the message with the particular message content given