如何在单击按钮时发送模态框?不和谐.py

问题描述 投票:0回答:1

单击按钮时出现错误 代码是这样的:

class ButtonModal(discord.ui.View):
  def __init__(self):
    super().__init__(timeout = None)
  @discord.ui.button(label = "Compile MODAL", emoji="📑",custom_id = "Role1", style = discord.ButtonStyle.primary)
  async def button1(self, interaction, button):
    user = interaction.user
    await interaction.response.send_modal(MyModal())

错误是这样的:

[0m ?[31mERROR   ?[0m ?[35mdiscord.ui.view?[0m Ignoring exception in view <ButtonModal timeout=None children=1> for item <Button style=<ButtonStyle.primary: 1> url=None disabled=False label='Compile MODAL' emoji=<PartialEmoji animated=False name='�' id=None> row=None>
?[31mTraceback (most recent call last):
  File "C:\Users\Administrator\Desktop\RequisBOT\bot-env\Lib\site-packages\discord\ui\view.py", line 425, in _scheduled_task
    await item.callback(interaction)
  File "c:\Users\Administrator\Desktop\RequisBOT\bot.py", line 67, in button1
    await interaction.response.send_modal(MyModal())
                                          ^^^^^^^^^
  File "C:\Users\Administrator\Desktop\RequisBOT\bot-env\Lib\site-packages\discord\ui\modal.py", line 135, in __init__
    super().__init__(timeout=timeout)
  File "C:\Users\Administrator\Desktop\RequisBOT\bot-env\Lib\site-packages\discord\ui\view.py", line 184, in __init__
    self.__weights = _ViewWeights(self._children)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\Desktop\RequisBOT\bot-env\Lib\site-packages\discord\ui\view.py", line 99, in __init__
    self.add_item(item)
  File "C:\Users\Administrator\Desktop\RequisBOT\bot-env\Lib\site-packages\discord\ui\view.py", line 116, in add_item
    index = self.find_open_space(item)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\Desktop\RequisBOT\bot-env\Lib\site-packages\discord\ui\view.py", line 106, in find_open_space
    raise ValueError('could not find open space for item')
ValueError: could not find open space for item?[0m

我尝试了很多解决方案,但没有找到解决方案

button view discord discord.py
1个回答
0
投票

我认为你的模型中有太多问题,因为最大值是 5,当我有更多问题时,我得到了相同的错误,所以我建议将模态分成不同的部分,这应该可以修复它

© www.soinside.com 2019 - 2024. All rights reserved.