用不和谐的模态来启发我。他们不会以视图或任何其他方式发送

问题描述 投票:0回答:1
class VerifyModal(discord.ui.Modal, title="Verify"):
  def __init__(self):
      super().__init__(timeout=None)
      self.username = discord.ui.TextInput(label="Fortnite Username", placeholder="Ninja...", required=True)


@bot.command()
async def verify_embed(ctx):
  embed = discord.Embed(
      title="Verify",
      color=discord.Color.green()
  )
  embed.add_field(name="How Do I Verify?", value="To Verify Please Click The Button below!", inline=False)

  verify_button = discord.ui.Button(label="Verify", style=discord.ButtonStyle.green, custom_id="verify", emoji="✅")

  async def verify_button_callback(interaction: discord.Interaction):
      view = VerifyModal()
      await ctx.send("Please fill in the form to verify", view=view)

  verify_button.callback = verify_button_callback
  button = discord.ui.View()
  button.add_item(verify_button)

  message = await ctx.send(embed=embed, view=button)

我问了chatgpt(他们没有帮助),然后我浏览了discord.py上的模态信息页面(什么也没找到)js需要有更多经验的人来帮助我

discord discord.py modal-dialog
1个回答
0
投票

您无法将模态框作为视图发送,您需要使用在按钮回调函数中获得的

interaction
对象,并使用
interaction.response.send_modal
函数。此外,您还需要更改您的
VerifyModal
类,
TextInput
应该是 class 变量而不是 instance 变量。

固定代码:

class VerifyModal(discord.ui.Modal, title="Verify"):
    username = discord.ui.TextInput(label="Fortnite Username", placeholder="Ninja...", required=True)

@bot.command()
async def verify_embed(ctx):
    embed = discord.Embed(
        title="Verify",
        color=discord.Color.green()
    )
    embed.add_field(name="How Do I Verify?", value="To Verify Please Click The Button below!", inline=False)

    verify_button = discord.ui.Button(label="Verify", style=discord.ButtonStyle.green, custom_id="verify", emoji="✅")

    async def verify_button_callback(interaction: discord.Interaction):
        view = VerifyModal()
        await interaction.response.send_modal(view)

    verify_button.callback = verify_button_callback
    button = discord.ui.View()
    button.add_item(verify_button)

    message = await ctx.send(embed=embed, view=button)
© www.soinside.com 2019 - 2024. All rights reserved.