Search code examples
pythondiscorddiscord.pybots

Method of viewing both the contents of a Discord reply and the message replied to?


I'm new to Discord bot making, however I'm fairly familiar with commands such as on_message and have a simple bot running at the moment that gives movie recommendations from a list when asked.

In the event that the bot is replied to, is there any way for it to read what the reply says along with what the replied-to message says? I'm trying to set it up so that, if the bot suggests a movie and that message is replied to with a specific word, it will remove that movie from the list.

Any help is greatly appreciated, thank you.


Solution

  • On discord.py, you can do referenced_message = original_msg.reference.resolved for the message object itself, and then referenced_message.content to get the message's content from the object

    Example code for your usage case:

    @bot.event
    async def on_message(message):
        replied_to = True if message.reference is not None else False
        if replied_to:
            message_reference = message.reference.resolved
            original_msg_content = message_reference.content
            #do extra logic about the movie stuff and then send the message away
    
    

    Hope it help!