question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`interaction.response.edit_message` Does Not Work in the `discord.ui.Modal` Class

See original GitHub issue

Summary

interaction.response.edit_message does not work in the callback function for the discord.ui.Modal class.

Reproduction Steps

  1. Clone the latest version of discord.py from GitHub.
  2. Use the code below.

Minimal Reproducible Code

class MyModal(Modal, title='Modal'):
    input_1 = TextInput(label="Short Input", placeholder="Placeholder Test")
    input_2 = TextInput(label="Longer Input", style=discord.TextStyle.long)
        
    async def on_submit(self, interaction: discord.Interaction):
        embed = discord.Embed(title="Your Modal Results", color=discord.Color.random())
        embed.add_field(name="First Input", value=self.input_1, inline=False)
        embed.add_field(name="Second Input", value=self.input_2, inline=False)
        await interaction.response.edit_message(embeds=[embed])
 
button = Button(label="Open Modal")
async def callback(interaction):
    modal = MyModal()
    await interaction.response.send_modal(modal)
button.callback = callback

view = View()
view.add_item(button)

await ctx.send("Hello", view=view)

Expected Results

The original message should be edited with an embed.

Actual Results

This is the error that comes in the modal window and the message is not edited. There is no error.

Intents

None

System Information

Python 3.10 discord.py master Branch (on GitHub)

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Infiniticitycommented, Mar 7, 2022

await interaction.message.edit(...)

Thanks! This worked.

2reactions
helish88commented, Mar 7, 2022

Then, is there a way to edit the message?

ping me on dpy server helish_88😈#7777

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interactions API Reference - discord.py - Read the Docs
Edits the original interaction response message. This is a lower level interface to InteractionMessage.edit() in case you do not want to fetch the...
Read more >
discord.py - modal not working i got an error but it doesn't ...
A Modal is a class that you send in your interaction response, not a command. ... Modal, title='Questionnaire Response'): name = ui.
Read more >
All you need to know about Buttons in Discord.py & Pycord
This is the Ultimate Python Guide on Buttons with Discord.py or Pycord. In this video, I talk about how to create buttons in...
Read more >
Discord MODALS in Discord.py are Here! - YouTube
In this video, we make/code a modal with Discord.py in Python. To make modals, you need to have Discord.py 2.0 (installation instructions ...
Read more >
Bot UI Kit - Pycord v2.3 Documentation
A decorator that attaches a button to a component. The function being decorated should have three parameters, self representing the discord.ui.View , the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found