#How to return value of Modal

1 messages · Page 1 of 1 (latest)

hallow agate
#

Hello! I would like to return the value of a modal to the command itself

For example I have a ban command, and the reason is provided through a sperate modal class,
now how can I use the results of modal inside the command?

class moderationReason(Modal):
    def __init__(self):
        super().__init__()

        self.add_item(
            InputText(
                label="Reason",
                placeholder="Add a reason for that instance",
                style=discord.InputTextStyle.long,
            )
        )

    async def callback(self, interaction: discord.Interaction):
code here

@commands.slash_command(description="Ban a user")
    async def ban(ctx, member: discord.Member):
        
        modal = moderationReason()

        await ctx.send_modal(modal)
        
        await member.ban('reason from modal')

All help is appreciated, please ping me on reply

civic prairie
#

@hallow agate try modal.children[0].value

#

so it will be

await member.ban(reason=modal.children[0].value)
hallow agate
#

trying it rn

#

discord.commands.errors.ApplicationCommandInvokeError: Application Command raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

shell steeple
#

You can try this:

modal = moderationReason()
await modal.wait()
reason = modal.children[0].value
await member.ban(reason)
#

modal.wait() waits for the modal to be submitted, then returns, so you block your script until then. This is similar to view.wait()