Discord Modal 更新后不更新 TextInput 标签 (Python)

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

过去几天我一直在学习如何编写机器人并有了大概的想法,但现在我遇到了这个问题:

class FormButtons(discord.ui.View):
    def __init__(self):
        super().__init__()
    
    @discord.ui.button(label="Moderator form", style=discord.ButtonStyle.gray)
    async def moderatorBtn(self, interaction: discord.Interaction, button: discord.ui.Button):
        rand = random.randint(0, len(config.moderator_questions) - 1)
        new_modal = moderation_modal()
        new_modal.question = ui.TextInput(label = config.moderator_questions[rand], style = discord.TextStyle.paragraph, placeholder = f"{rand}", required = True, max_length = 128)
        await interaction.response.send_modal(new_modal)
        await new_modal.wait()
            

class moderation_modal(ui.Modal, title = "Example modal"):
    question = ui.TextInput(label = "Hello!", style = discord.TextStyle.paragraph, placeholder = "Not sure!", required = True, max_length = 128)
    
    async def on_submit(self, interaction: discord.Interaction):
        channel = bot.get_channel(config.form_result_channel)
        embed = discord.Embed(title = self.title, description = f"**{self.answer.label}**\n{self.answer}", timestamp = datetime.now(), color = discord.Colour.blue())
        embed.set_author(name = interaction.user, icon_url = interaction.user.avatar)
        await channel.send(embed = embed)
        await interaction.response.send_message(content=config.response_completed_form, ephemeral=True)

所以,我有一个带有字符串的数组,它代表用户的不同问题,并希望他们更改标题

new_modal.question.label
。即使用户重新打开模式而不提交它,我也需要生成新问题。

我尝试通过简单地在聊天中输入其标题来检查

new_modal.title
是否已更改,一切正常,每次我按“主持人表单”按钮时标题都会更改,但当我尝试发送模式时,它只是保持不变如
moderation_modal.question.title

是否有更新模态 UI 的功能或任何其他解决方法,以便每次用户重新打开模态时标题都会更改?

python forms discord modal-dialog bots
1个回答
0
投票

我在使用 Discord.js 调试一些模态值和占位符时遇到了这个问题。我的 Discord 桌面应用程序上的模式不会立即反映我对机器人模式代码所做的更改。

我能够通过完全关闭我的 Discord 桌面应用程序并重新启动来强制模式更改。

可能有缓存需要清理,但我目前不知道。

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