Skip to content Skip to sidebar Skip to footer

Get A Message's Content From Their Id

Is there a way to get a message's content from its id? If so, how can I do that? I've read through its documentation but I found nothing. In the documentation, it says you can get

Solution 1:

If you don't have the channel id but only the message id, you just need to loop through your accessible channels and check which one(s)* have the message that matches your id.

from discord import NotFound


for channel in client.get_all_channels():
    try:
        msg = await channel.get_message(id)
    except NotFound:
        continueprint(msg.content)

# where `id` is the message id and `client` is the bot or user

* Message id isn't unique to the system, that is why the only way is to loop through all available channels, since message id is only unique to the channel. It is possible (quite unlikely though) to match two distinct messages with the same id from two different channels.

Solution 2:

In the rewrite branch of discord.py you can use the get_message() coroutine (documentation found here) to find a message using its ID. I'm not sure if there's a way to do it in 0.16.12

Post a Comment for "Get A Message's Content From Their Id"