How to get the interaction response message object - discord.py

Viewed 34

Lately, I've been developing a command of sorts, which requires the interaction message in order to do some operations (like delete it after some time when a view times out, which requires the message to be assigned as an attribute to the view).

However, the problem is that my code always returns the interaction message as None; I've done some research, and found that - to my dismay - interaction responses don't return their interaction message. Here's a minimal reproducible example (Do note that I'm using cogs):

@app_commands.command()
async def command(self, interaction: discord.Interaction):
    message = await interaction.response.send_message('Hey!')
    print(message)

This command prints None whenever I run it; however, I want it to print the message object that's dispatched by the interaction response. Is there any other way to do this?

Any help would be greatly appreciated.

1 Answers

await interaction.original_response() returns the message of the interaction response.

Integrating this into the full code:

@app_commands.command()
async def command(self, interaction: discord.Interaction):
    await interaction.response.send_message('Hey!')
    message = await interaction.original_response()
    print(message)
Related