-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Modals with Select fields #9007
-
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,).
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes, like I said, Discord started disallowing select menus in modals back in August.
You'll have to use views and modals separately.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
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 :(
Beta Was this translation helpful? Give feedback.
All reactions
-
There's nothing discord.py can do about it.
You can discuss the feature request at https://github.com/discord/discord-api-docs/discussions.
Beta Was this translation helpful? Give feedback.
All reactions
-
@Harmon758 ok thx man :)
Beta Was this translation helpful? Give feedback.
All reactions
-
String selects got introduced about 3 weeks back:
https://discord.com/developers/docs/change-log#introducing-new-modal-components
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1