Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the most recent message of a channel in discord.py?

Is there a way to get the most recent message of a specific channel using discord.py? I looked at the official docs and didn't find a way to.

like image 768
leo848 Avatar asked Jan 25 '23 17:01

leo848


1 Answers

I've now figured it out by myself:

For a discord.Client class you just need these lines of code for the last message:


(await self.get_channel(CHANNEL_ID).history(limit=1).flatten())[0]

If you use a discord.ext.commands.Bot @thegamecracks' answer is correct.

like image 129
leo848 Avatar answered Jan 29 '23 20:01

leo848