Search code examples
pythondiscorddiscord.py

Discord.py - Is there a way to edit a sent slash command message from a bot?


I am trying to make a discord bot that gets images from dalle. I have the api set up and it will send back and image link, but I am using slash commands in discord and the request from dalle takes longer than discord allows bots to take. I am trying to find out if there is a way to edit a message, as I have resulted in sending, 'Waiting on DALLE's response...' then editing it after the DALLE image has come back. I would like it to send back the image as soon as the image url has come back. Here is my code:

@bot.tree.command(name="image")
@app_commands.describe(arg = "The bot will respond with DALLE's response to this query")
async def image(interaction: discord.Interaction, arg: str):
    messageToEdit = await interaction.response.send_message("Waiting for DALL E's response...")
    response = await getDALLEImage(arg)
    await messageToEdit.channel.edit_message(messageToEdit, content=response)

The way to edit there is just a way I tried, I can't seem to find how to edit it, and maybe it's because it's a slash command and not a normal command.

Thanks.


Solution

  • Maybe this helps: https://github.com/Rapptz/discord.py/discussions/9101

    Alternatively you could just send a second message after the "Waiting for DALL E's response..." with the image link from DALLE.