'Pycord Discord bot Read DM History, How to get DM Channel History

I am using pycord and am trying to have my discord bot look through its dm messages with a particular user to know if it has already sent a specific message to that user or not. Is this possible?

I have found plenty of examples for how to have the discord bot respond to "on_message()" but this is not what i want. I want to get the history of previously sent messages (or None if no dm history). Is this possible?

Another use case would be: I want the bot to edit a message it sent to a user in DM after they add a reaction to the message. I am able to have the bot get triggered when the user adds a reaction

@commands.Cog.listener()
async def on_raw_reaction_add(self, ctx: discord.RawReactionActionEvent):

But the ctx in this function only contains a channel_id and message_id, so I need some way of getting the DiscordChannel with the channel_id and then get the DiscordMesage with the message_id.

This seems to be a missing feature in pycord :'(



Solution 1:[1]

Alright. So after reading the Doc. I have come up with a way you can do this.

The ctx : RawReactionActionEvent has the attribute user_id. With this you can fetch the user using user = await self.client.fetch_user(user_id). With the user object there is an attribute dm_channel. With this it returns the DMChannel. If a dm was not created with the user, it returns None. Then you can fetch the message with the message ID. I think this is what you mean. If not I can maybe find a different way.

https://docs.pycord.dev/en/master/api.html#discord.RawReactionActionEvent

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1