Advertisement
NaroxEG

Discord.py Modals By Narox

Sep 20th, 2023 (edited)
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3.  
  4.  
  5. client = commands.Bot(command_prefix="-", intents=discord.Intents.default())
  6. tree = client.tree
  7.  
  8.  
  9. @client.event
  10. async def on_ready():
  11.     synced = await tree.sync()
  12.     print(f"Synced {len(synced)} Command(s)")
  13.  
  14.  
  15. class MyView(discord.ui.View):
  16.     def __init__(self):
  17.         super().__init__(timeout=None)
  18.  
  19.     @discord.ui.button(label="MyButton", style=discord.ButtonStyle.red)
  20.     async def MyButton(self, interaction: discord.Interaction, button: discord.Button):
  21.         await interaction.response.send_modal(MyModal())
  22.  
  23.  
  24. class MyModal(discord.ui.Modal):
  25.     def __init__(self):
  26.         super().__init__(title="MyModal")
  27.  
  28.     name = discord.ui.TextInput(
  29.         label="Name:",
  30.         placeholder="Type your name here.."
  31.     )
  32.  
  33.     about = discord.ui.TextInput(
  34.         label="About:",
  35.         placeholder="Introduce yourself",
  36.         style=discord.TextStyle.long,
  37.         max_length=300,
  38.         required=False
  39.     )
  40.  
  41.     async def on_submit(self, interaction: discord.Interaction):
  42.         await interaction.response.send_message(f"Thanks for your response, {self.name.value}", ephemeral=True)
  43.  
  44.  
  45. @tree.command(name="test", description="test modal")
  46. async def Test(interaction: discord.Interaction):
  47.     await interaction.response.send_message("Test", view=MyView())
  48.  
  49.  
  50. client.run("TOKEN")
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement