Twiggeh
Twiggeh

Reputation: 1160

DiscordJS - get all DM Channels

I want to retrieve all dm-channels and all messages in those channels that a bot has sent.

This should retrieve all channels the bot has access to. But it seems it only retrieves guild channels.

client.channels.cache.entries()

The Discord Docs say that I have to explicitly fetch the DM's but I am not sure how to do that ...

.channels All of the Channels that the client is currently handling, mapped by their IDs - as long as sharding isn't being used, this will be every channel in every guild the bot is a member of. Note that DM channels will not be initially cached, and thus not be present in the Manager without their explicit fetching or use.

Type: ChannelManager

Upvotes: -1

Views: 4019

Answers (1)

Twiggeh
Twiggeh

Reputation: 1160

This is impossible, since dm's are never in the api's payload.

To get the messages of a dm you need to know the users id that has a dm open to the bot. From that point you can open a dm from the User object and then fetch all messages.

After that the channel cache will contain the dm for the session that the bot is online.

Upvotes: 1

Related Questions