Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Modals with Select fields #9007

Answered by Harmon758
jbaumgarten asked this question in Q&A
Discussion options

Hi guys,

Does modal still work with Select fields?

import discord.app_commands
import discord.ui
token = #TOKEN here
client = discord.Client(intents=discord.Intents.default())
tree = discord.app_commands.CommandTree(client)
@tree.command(
 name="modal",
 description="Send modal."
)
async def modal(ctx:discord.Interaction):
 modal=discord.ui.Modal(title="Hello!")
 modal.add_item(discord.ui.Select(min_values=1, max_values=1, options=[discord.SelectOption(label='A'), discord.SelectOption(label='B')]))
 await ctx.response.send_modal(modal)
@client.event
async def on_ready():
 print("ready")
 await tree.sync()
client.run(token)

produces the following error

2022年10月17日 21:48:43 INFO discord.client logging in using static token
2022年10月17日 21:48:45 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: 8b1b211145fe79255d392b7f32380946).
ready
2022年10月17日 21:49:05 ERROR discord.app_commands.tree Ignoring exception in command 'modal'
Traceback (most recent call last):
 File "/Users/toto/opt/anaconda3/envs/dev_env/lib/python3.10/site-packages/discord/app_commands/commands.py", line 851, in _do_call
 return await self._callback(interaction, **params) # type: ignore
 File "/Users/toto/Desktop/workspace/test.py", line 16, in modal
 await ctx.response.send_modal(modal)
 File "/Users/toto/opt/anaconda3/envs/dev_env/lib/python3.10/site-packages/discord/interactions.py", line 852, in send_modal
 await adapter.create_interaction_response(
 File "/Users/toto/opt/anaconda3/envs/dev_env/lib/python3.10/site-packages/discord/webhook/async_.py", line 221, in request
 raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In data.components.0.components.0: Value of field "type" must be one of (4,).
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
 File "/Users/toto/opt/anaconda3/envs/dev_env/lib/python3.10/site-packages/discord/app_commands/tree.py", line 1240, in _call
 await command._invoke_with_namespace(interaction, namespace)
 File "/Users/toto/opt/anaconda3/envs/dev_env/lib/python3.10/site-packages/discord/app_commands/commands.py", line 876, in _invoke_with_namespace
 return await self._do_call(interaction, transformed_values)
 File "/Users/toto/opt/anaconda3/envs/dev_env/lib/python3.10/site-packages/discord/app_commands/commands.py", line 869, in _do_call
 raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'modal' raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In data.components.0.components.0: Value of field "type" must be one of (4,).
You must be logged in to vote

First of all, you'll want to regenerate your credentials now, if you haven't already.

This was never supported by Discord, and they started disallowing it back in August.

discord/discord-api-docs#5303 (comment)

For code block usage, see https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks.

Replies: 2 comments 5 replies

Comment options

First of all, you'll want to regenerate your credentials now, if you haven't already.

This was never supported by Discord, and they started disallowing it back in August.

discord/discord-api-docs#5303 (comment)

For code block usage, see https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks.

You must be logged in to vote
5 replies
Comment options

Hi @Harmon758

My credentials are already regenerated thx ^^

I read the topic: #8312 that's why I thought I can use select in modals
Select only works in view?

What kind of items should I use to handle Select AND TextInput?

Comment options

Yes, like I said, Discord started disallowing select menus in modals back in August.

You'll have to use views and modals separately.

Comment options

You'll have to use views and modals separately.

That's a bit ugly to be forced to use several kind of items to handle text inputs and select :(

Comment options

There's nothing discord.py can do about it.

You can discuss the feature request at https://github.com/discord/discord-api-docs/discussions.

Comment options

@Harmon758 ok thx man :)

Answer selected by jbaumgarten
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /