Jelajahi Sumber

testing with modals and views

BaumSplitter41 3 minggu lalu
induk
melakukan
ae590b0f46
1 mengubah file dengan 24 tambahan dan 0 penghapusan
  1. 24 0
      TEST_BOT_BAUM/main.py

+ 24 - 0
TEST_BOT_BAUM/main.py

@@ -196,7 +196,31 @@ async def ban(
     except Exception as e:
         await ctx.respond(f"Unexpected error: {e}", ephemeral=True)
 
+#---------------------------------------------------------------------------------------#
+#TESTs of Modals and Views
+
+
+class MyModal(discord.ui.Modal):
+    def __init__(self, *args, **kwargs) -> None:
+        super().__init__(*args, **kwargs)
+
+        self.add_item(discord.ui.InputText(label="Short Input"))
+        self.add_item(discord.ui.InputText(label="Long Input", style=discord.InputTextStyle.long))
+
+    async def callback(self, interaction: discord.Interaction):
+        embed = discord.Embed(title="Modal Results")
+        embed.add_field(name="Short Input", value=self.children[0].value)
+        embed.add_field(name="Long Input", value=self.children[1].value)
+        await interaction.response.send_message(embeds=[embed])
+
+class MyView(discord.ui.View):
+    @discord.ui.button(label="Send Modal")
+    async def button_callback(self, button, interaction):
+        await interaction.response.send_modal(MyModal(title="Modal via Button"))
 
+@bot.slash_command()
+async def send_modal(ctx):
+    await ctx.respond(view=MyView())