How do I send a modal when a button is clicked?


This Content is from Stack Overflow. Question asked by Alex Satoru

Im attempting to send a modal when the “ask” button is clicked from the embed. enter image description here

Error message:

AttributeError: 'Button' object has no attribute 'response'
class AskModal(nextcord.ui.Modal):
    def __init__(self):
        self.emQuestion = nextcord.ui.TextInput(label = "Question", required = True, placeholder = "What level shall I reach to stay in the group?", style = nextcord.TextInputStyle.paragraph)

    async def callback(self, interaction: nextcord.Interaction) -> None:
        question = self.emQuestion.value
        channel = bot.get_channel(1017234639770894377)
        questionmsg = (f"{question} ^ {}")
        message = ("Your question has been sent!")

        await channel.send(questionmsg)

        return await interaction.response.send_message(message, ephemeral=True)

class askbutton(nextcord.ui.View):
    def __int__(self):

    @nextcord.ui.button(label="Ask", style=, custom_id = "ask button")
    async def asks(self, interaction: nextcord.Interaction, button: nextcord.ui.Button):
        return await interaction.response.send_modal(AskModal())

async def ask(ctx) :
    embed = nextcord.Embed(title="QNA", description="・You may ask a question by using the slash command `/ask`nn・You'll be notified that your question has been answered by receiving a ping in the <#928507764714651698> channel", color= 0x303136)
    await ctx.send(embed = embed, view = askbutton())

The ask button doesn’t respond when the button is clicked, did I miss something?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?