【发布时间】:2022-12-18 18:52:24
【问题描述】:
【问题讨论】:
-
Modal 目前在 Nextcord 中不可用。你可以尝试使用pycord
-
Modal 将在 nextcord v2.0.0a10 中可用
标签: python discord discord.py nextcord
【问题讨论】:
标签: python discord discord.py nextcord
您可以在此处找到 Nextcord 中模态的示例:
https://github.com/nextcord/nextcord/blob/master/examples/modals/
class Pet(nextcord.ui.Modal):
def __init__(self):
super().__init__("Your pet") # Modal title
# Create a text input and add it to the modal
self.name = nextcord.ui.TextInput(
label="Your pet's name",
min_length=2,
max_length=50,
)
self.add_item(self.name)
# Create a long text input and add it to the modal
self.description = nextcord.ui.TextInput(
label="Description",
style=nextcord.TextInputStyle.paragraph,
placeholder="Information that can help us recognise your pet",
required=False,
max_length=1800,
)
self.add_item(self.description)
async def callback(self, interaction: nextcord.Interaction) -> None:
"""This is the function that gets called when the submit button is pressed"""
response = f"{interaction.user.mention}'s favourite pet's name is {self.name.value}."
if self.description.value != "":
response += f"
Their pet can be recognized by this information:
{self.description.value}"
await interaction.send(response)
@bot.slash_command(
name="pet",
description="Describe your favourite pet",
guild_ids=[TESTING_GUILD_ID],
)
async def send(interaction: nextcord.Interaction):
# sending the modal on an interaction (can be slash, buttons, or select menus)
modal = Pet()
await interaction.response.send_modal(modal)
【讨论】: