如何确保模态窗口关闭后,再次打开时保存其中输入的数据? 我查看了有关模态的整个 discord.py 文档,但我仍然找不到如何做到这一点...... 这是代码,请帮帮我!
class SupportApplicationModal(ui.Modal):
def __init__(self):
super().__init__(title="Apply for Support")
self.add_item(ui.TextInput(
label="Name and age",
placeholder="Enter your name and age"
))
self.add_item(ui.TextInput(
label="Do you have an experience in this sphere?",
placeholder="If yes, please tell us in more detail...",
style=discord.TextStyle.long,
max_length=150
))
self.add_item(ui.TextInput(
label="What device can you use for work?",
placeholder="PC / Phone"
))
self.add_item(ui.TextInput(
label="Is your microphone good?",
placeholder="Yes / No"
))
async def on_submit(self, interaction: discord.Interaction):
embed = discord.Embed(
title="New application for Support",
description=(
f"**1) User applied:**\n{interaction.user.mention}\n\n"
f"**2) Name and age:**\n```{self.children[0].value}```\n"
f"**3) Does he had an experience?:**\n```{self.children[1].value}```\n"
f"**4) Device using:**\n```{self.children[2].value}```\n"
f"**5) Microphone presence:**\n```{self.children[3].value}```\n"
)
)
await interaction.response.send_message(
"Thank you for **applying for Support**! We will try to review it **as soon as possible**. :)",
ephemeral=True
)
channel = interaction.guild.get_channel(1278424511489773599)
await channel.send(content=f"<@&{ALLOWED_SUPPORT_TO_MANAGE}>", embed=embed)
class MainRoleSelectView(ui.View):
def __init__(self):
super().__init__(timeout=None)
@ui.select(
placeholder="Select the role",
options=[
discord.SelectOption(
label="Support",
description="Select and fill an application for Support",
emoji="<:support:1288778117917179995>"
),
discord.SelectOption(
label="Moderator",
description="Select and fill an application for Moderator",
emoji="<:moderator:1288778357202489345>"
)],
min_values=1,
max_values=1
)
async def select_role(self, interaction: discord.Interaction, select: ui.Select):
selected_role = select.values[0]
if selected_role == "Support":
await interaction.response.send_modal(SupportApplicationModal())
elif selected_role == "Moderator":
await interaction.response.send_modal(ModeratorApplicationModal())
await asyncio.sleep(2)
select.values.clear()
await interaction.edit_original_response(view=self)
我只想在关闭 Discord 中的模式窗口后保留输入的数据。当您再次打开它时,输入的数据仍保留在其字段中。
实现目标的方法是:
on_submit
方法存储用户在字段中输入的数据;default
属性 TextImput。