Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- client = commands.Bot(command_prefix="-", intents=discord.Intents.default())
- tree = client.tree
- @client.event
- async def on_ready():
- synced = await tree.sync()
- print(f"Synced {len(synced)} Command(s)")
- class MyView(discord.ui.View):
- def __init__(self):
- super().__init__(timeout=None)
- @discord.ui.button(label="MyButton", style=discord.ButtonStyle.red)
- async def MyButton(self, interaction: discord.Interaction, button: discord.Button):
- await interaction.response.send_modal(MyModal())
- class MyModal(discord.ui.Modal):
- def __init__(self):
- super().__init__(title="MyModal")
- name = discord.ui.TextInput(
- label="Name:",
- placeholder="Type your name here.."
- )
- about = discord.ui.TextInput(
- label="About:",
- placeholder="Introduce yourself",
- style=discord.TextStyle.long,
- max_length=300,
- required=False
- )
- async def on_submit(self, interaction: discord.Interaction):
- await interaction.response.send_message(f"Thanks for your response, {self.name.value}", ephemeral=True)
- @tree.command(name="test", description="test modal")
- async def Test(interaction: discord.Interaction):
- await interaction.response.send_message("Test", view=MyView())
- client.run("TOKEN")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement