#Modal Options
1 messages · Page 1 of 1 (latest)
I've already tried Google, but I couldn't find anything
Is that possible?
Happy to ping
Which option?
all good does that come from the callback or the command?
b!rtfm pycord Option
second one
I don't know about callbacks, but that is how you would use it in an interaction command
Thank you anyway..
async def test(ctx: discord.ApplicationContext, choice: discord.Option(str, "Enter your string here...", default="No Input!)):
or
async def test(ctx: discord.ApplicationContext, choice: discord.Option(str, "Enter your string here...") = "No Input!"):
https://docs.pycord.dev/en/master/api.html#option gives examples on how to use discord.Option in typehinting the parameter
the user would input any random string they want in the case of my example
you can also set it to take different types like ints, discord.Member, etc.
Unfortunately didn't help..
test = discord.ui.InputText(
style=discord.InputTextStyle.short,
label="Title",
required=False
)
this should work?
I have one more question and I hope I'm not annoying you, but how can I add a watermark?
what do you mean by watermark?
so yk?
inside discord.ui.InputText set the placeholder field
so
test = discord.ui.InputText(
style=discord.InputTextStyle.short,
label="Title",
required=False,
placeholder="Test"
)
yes you can
So, `class MyModal(discord.ui.Modal):
def init(self, *args, **kwargs) -> None:
super().init(*args, **kwargs)
self.add_item...` ?
nothing needs to change in the modal class
So like normal like here: https://guide.pycord.dev/interactions/ui-components/modal-dialogs/ ?
Learn how you can implement Modals in your Discord Bot with Pycord!
yeah
and then just import it (if it's in another file) in your cog and use it like normal
Ok thanks 😄
you're welcome 🙂
Hey im sorry what is wrong with the setup?
The Error:
Traceback (most recent call last):
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\cog.py", line 723, in _load_from_module_spec
setup(self)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\extensions\Modal.py", line 25, in setup
bot.add_cog(Modals(bot))
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\ui\modal.py", line 47, in __init__
loop = asyncio.get_running_loop()
RuntimeError: no running event loop
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zReaxrYT\PycharmProjects\Discord\main.py", line 14, in <module>
bot.load_extension(f"extensions.{filename[:-3]}")
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\cog.py", line 783, in load_extension
self._load_from_module_spec(spec, name)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\cog.py", line 728, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.errors.ExtensionFailed: Extension 'extensions.Modal' raised an error: RuntimeError: no running event loop
Process finished with exit code 1
The Code
i have copy paste made to test
I'm really sorry if I'm annoying you
Modal Options
so how can I not create a cog with modals?
Huh how both classes in the same file?
class Modals(...):
pass
class MyCog(...):
pass```
make them both top level indentation
and then I can start the bot again? so is it a cog?
yes
replace that with the
.
So i have this:
import discord
from discord.ext import commands
from discord.commands import slash_command, Option
class Modals(discord.ui.Modal):
def __int__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Short Input"))
self.add_item(discord.ui.InputText(label="Long Input", style=discord.InputTextStyle.long))
async def callback(self, interaction: discord.Interaction):
embed = discord.Embed(title="Modal Results")
embed.add_field(name="Short Input", value=self.children[0].value)
embed.add_field(name="Long Input", value=self.children[1].value)
await interaction.response.send_message(embeds=[embed])
def setup(bot):
bot.add_cog(Modals(bot))
that's not a cog
the error is still there
huh?
you're trying to add a Modal to the bot when it's expecting a Cog
import discord
from discord.ext import commands
from discord.commands import slash_command, Option
class Modals(discord.ui.Modal):
def __int__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Short Input"))
self.add_item(discord.ui.InputText(label="Long Input", style=discord.InputTextStyle.long))
async def callback(self, interaction: discord.Interaction):
embed = discord.Embed(title="Modal Results")
embed.add_field(name="Short Input", value=self.children[0].value)
embed.add_field(name="Long Input", value=self.children[1].value)
await interaction.response.send_message(embeds=[embed])
class MyCog(commands.Cog):
pass
def setup(bot):
bot.add_cog(MyCog(bot))```
you need to do this if you want to use a cog ^
Thanks and now I can use modals?
sure
and the slash command? Can he still go in to run the modal?
import discord
from discord.ext import commands
from discord.commands import slash_command, Option
class Modals(discord.ui.Modal):
def __int__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Short Input"))
self.add_item(discord.ui.InputText(label="Long Input", style=discord.InputTextStyle.long))
async def callback(self, interaction: discord.Interaction):
embed = discord.Embed(title="Modal Results")
embed.add_field(name="Short Input", value=self.children[0].value)
embed.add_field(name="Long Input", value=self.children[1].value)
await interaction.response.send_message(embeds=[embed])
@slash_command()
async def lolmodal(self, ctx):
the_modal = Modals(title="Test Modal")
await ctx.send_modal(the_modal)
class MyCog(commands.Cog):
pass
def setup(bot):
bot.add_cog(MyCog(bot))
no, the slash command goes in the cog
import discord
from discord.ext import commands
from discord.commands import slash_command, Option
class Modals(discord.ui.Modal):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Short Input"))
self.add_item(discord.ui.InputText(label="Long Input", style=discord.InputTextStyle.long))
async def callback(self, interaction: discord.Interaction):
embed = discord.Embed(title="Modal Results")
embed.add_field(name="Short Input", value=self.children[0].value)
embed.add_field(name="Long Input", value=self.children[1].value)
await interaction.response.send_message(embeds=[embed])
class MyCog(commands.Cog):
@slash_command()
async def lolmodal(self, ctx):
the_modal = Modals(title="Test Modal")
await ctx.send_modal(the_modal)
def setup(bot):
bot.add_cog(MyCog(bot))```
But not possible.. I want to apologize again for wasting your time
Ignoring exception in command lolmodal:
Traceback (most recent call last):
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\commands\core.py", line 122, in wrapped
ret = await coro(arg)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\commands\core.py", line 825, in _invoke
await self.callback(self.cog, ctx, **kwargs)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\extensions\Modal.py", line 24, in lolmodal
await ctx.send_modal(the_modal)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\interactions.py", line 815, in send_modal
await adapter.create_interaction_response(
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\webhook\async_.py", line 213, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In data.components: This field is required
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\bot.py", line 1098, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\commands\core.py", line 331, in invoke
await injected(ctx)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\commands\core.py", line 128, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In data.components: This field is required
correct def __int__ to def __init__ and you should be good lmao
1
2
thanks @coral mountain 🙂
👍
@copper geyser it should be init, not int ^^