是否可以链接多个Discord模态框? [discord.py]

huangapple go评论74阅读模式
英文:

Is it possible to chain several Discord modals? [discord.py]

问题

我的目标是在 Discord 中链接多个不同的模态对话框,以创建一个连续的表单,因为 Discord 不允许在单个模态对话框中添加超过 5 个项目或“问题”。

目标是在 modal_1 和 modal_2 中各有 5 个问题。每当用户运行命令时,将显示 modal_1。完成后,用户将提交 modal_1,随后会出现 modal_2。

不幸的是,我所有的尝试都没有成功,Discord 在提交后没有关闭第一个模态对话框,而是返回错误:“出了些问题,请重试”。这个错误不是代码错误,而是在 Discord 模态对话框中。

以下是用于说明我在做什么的代码片段:

class Modal_2(discord.ui.Modal,title="Modal_2"):
    question_1 = discord.ui.TextInput(label="这是第二个问题")

    async def on_sumbit(self,interaction:discord.Interaction):
        await interaction.response.send_message(content="感谢您的回答")

class Modal_1(discord.ui.Modal,title="Modal_1"):
    question_1 = discord.ui.TextInput(label="这是第一个问题")

    async def on_sumbit(self,interaction:discord.Interaction):
         await interaction.response.send_modal(Modal_2())

class main(commands.Cog):
    def __init__(self,bot):
          self.bot = bot

    @app_commands.command(name="survey")
    async def main(self,interaction:discord.Interaction)
         await interaction.response.send_modal(Modal_1())

运行命令后,会显示第一个模态对话框。但是当提交后,第二个模态对话框从不显示,也不会关闭第一个模态对话框。只会在提交后在第一个模态对话框中返回错误:“出了些问题,请重试”,但控制台中不会显示实际的“代码”错误或异常。

英文:

My goal is to chain or link several different discord modals after one-another in order to create a continuous form since Discord does not allow to add more than 5 items or "questions" per modal.

The goal is to have modal_1 and modal_2 with 5 questions in each. Every time a command is ran by a user, modal_1 would be displayed. After completion, the user would submit modal_1, after which modal_2 would appear.

Sadly, all my tries were unsuccessful, with Discord not closing the first modal after submitting it and instead returning the error: "Something went wrong, try again". This error is not a code error, but inside of the Discord modal.

Here is a code snippet to illustrate what I am doing:

class Modal_2(discord.ui.Modal,title="Modal_2"):
    question_1 = discord.ui.TextInput(label="That's the second question")

    asnyc def on_sumbit(self,interaction:discord.Interaction):
        await interaction.response.send_message(content="Thanks for your input")

class Modal_1(discord.ui.Modal,title="Modal_1"):
    question_1 = discord.ui.TextInput(label="That's the first question")

    asnyc def on_sumbit(self,interaction:discord.Interaction):
         await interaction.response.send_modal(Modal_2())

class main(commands.Cog):
    def __init__(self,bot):
          self.bot = bot

    @app_commands.command(name="survey")
    async def main(self,interaction:discord.Interaction)
         await interaction.response.send_modal(Modal_1())

After the command is run, shows the first modal. Though when submitted, the second modal never shows up nor is the first modal dismissed. It only returns the error: "Something went wrong, try again" within the first modal after submitting it, but now actual "code" error or exception is shown in the console.

答案1

得分: 0

无法在MODAL_SUBMIT交互的回调中使用MODAL。根据Discord开发者门户的此部分,可以看到MODAL不能作为MODAL_SUBMIT交互的回调。

根据数据的类型,我建议要么使用表单网页,要么尝试使用View Widgets,特别是TextInputs,因为你可以使用它们发送任意数量的消息。

英文:

No, you can't. Looking in this section of Discord's Developers' Portal, you can read that MODAL can't be the callback of a MODAL_SUBMIT interaction.

Depending on what the data is, I would either use a form webpage or try to do something with the View Widgets, especially TextInputs, since you can send as many messages with these as you want.

huangapple
  • 本文由 发表于 2023年7月20日 19:22:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76729345.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定