#I am creating a modal but im getting components out of length

1 messages · Page 1 of 1 (latest)

gritty valve
#
        def __init__(self):
            super().__init__()
        @discord.ui.button(label="Move", style=discord.ButtonStyle.blurple, emoji=":handshake:") 
        async def accept_button(self, button, interaction):   
            if interaction.user != game.get_current_player():
                await interaction.response.send_message(f"It is not your turn to move.", ephemeral=True)
                return     
            button.disabled = True
            button.label = "Moved"
            await interaction.response.send_modal(Moving())
            await interaction.response.edit_message(view=self)
            await ctx.respond(f"{interaction.user} has moved!")
class Moving(discord.ui.Modal):
    def __init__(self):
        super().__init__(title="Hi")

    # This will be a short input, where the user can enter their name
    # It will also have a placeholder, as denoted by the `placeholder` kwarg.
    # By default, it is required and is a short-style input which is exactly
    # what we want.
    name = discord.ui.InputText(
        label='Name',
        placeholder='Your move here',
    )

    async def on_submit(self, interaction: discord.Interaction):
        await interaction.response.send_message(f'you have moved, {self.name.value}!', ephemeral=True)
#

hi, im getting this error in response:
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body In data.components: Must be between 1 and 5 in length.

iron iris
#

you will need to do this in the init

frozen glacierBOT
#

examples/modal_dialogs.py lines 14 to 43

class MyModal(discord.ui.Modal):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(
            discord.ui.InputText(
                label="Short Input",
                placeholder="Placeholder Test",
            ),
            discord.ui.InputText(
                label="Longer Input",
                value="Longer Value\nSuper Long Value",
                style=discord.InputTextStyle.long,
            ),
            *args,
            **kwargs,
        )

    async def callback(self, interaction: discord.Interaction):
        embed = discord.Embed(
            title="Your Modal Results",
            fields=[
                discord.EmbedField(
                    name="First Input", value=self.children[0].value, inline=False
                ),
                discord.EmbedField(
                    name="Second Input", value=self.children[1].value, inline=False
                ),
            ],
            color=discord.Color.random(),
        )
        await interaction.response.send_message(embeds=[embed])```
gritty valve
#

wait so how do i put the title of the modal?

iron iris
gritty valve
#

how?

#

its giving me an error

iron iris
#

smth like super().__init__(... , title="", ...)

iron iris
gritty valve
#

this one: TypeError: Moving.__init_subclass__() takes no keyword arguments

iron iris
#

pogbruh wait what did you do?

gritty valve
#

lemms hwo u

#

wait a sec

#

is this right?

iron iris
# gritty valve

hmm looks right. but you never used add_item or passed the input text to the init

#

also, are you defining the class inside smth?

#

dont do that

#

define the class in the global scope

gritty valve
gritty valve
#

like whats it for?

iron iris
gritty valve
#

oh

gritty valve
# gritty valve

also the error in this code is that the brackets arent closed

#

but they r

iron iris
#

smth like

def __init__(...):
  super().__init__(...)
  name = ui.InputText(...)
  some_text = ui.InputText(...)
  self.add_item(name)
  self.add_item(some_text)
gritty valve
#

oh ic

#

but like where does the title go

iron iris
iron iris
gritty valve
#

oh ic

iron iris
#

you could also pass it to the init of your modal subclass and pass it up using *args, **kwargs

gritty valve
#

oh ok

#

when i put it in the super init it says this:

#

oh waite

#

do i have to add -> None?

iron iris
#

i think that is the issue

gritty valve
#

oh yeah thats also an issue i thinnk its the order or smth

#

like title after the inputtext

iron iris
#

yea

gritty valve
#

oo it worked

#

tysm

#

?solved

#

how doi solve this

iron iris
faint kiteBOT
gritty valve
#

oh ic

#

.close

faint kiteBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @frozen glacier.