Advertisement
NaroxEG

Discord.py select menus

Jan 29th, 2024 (edited)
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3.  
  4. client = commands.Bot(command_prefix="!", intents=discord.Intents.default())
  5. tree = client.tree
  6.  
  7. @client.event
  8. async def on_ready():
  9.     print(f"Logged in as {client.user}")
  10.     synced = await tree.sync()
  11.     print(f"Synced {len(synced)} Command(s).")
  12.  
  13. class Dropdown(discord.ui.Select):
  14.     def __init__(self):
  15.         options = [
  16.             discord.SelectOption(label="Select 1", description="First Select Option"),
  17.             discord.SelectOption(label="Select 2", description="Second Select Option"),
  18.             discord.SelectOption(label="Select 3", description="Third Select Option"),
  19.             discord.SelectOption(label="Select 4", description="Fourth Select Option"),
  20.             discord.SelectOption(label="Select 5", description="Fifth Select Option"),
  21.         ]
  22.         super().__init__(placeholder="Select an element", min_values=2, max_values=3, options=options)
  23.  
  24.     async def callback(self, interaction: discord.Interaction):
  25.         elements = ",".join(x for x in self.values)
  26.         await interaction.response.send_message(f"You chose {elements}")
  27.  
  28. class DropdownView(discord.ui.View):
  29.     def __init__(self):
  30.         super().__init__()
  31.         self.add_item(Dropdown())
  32.  
  33.  
  34. @tree.command(name="select")
  35. async def _select(interaction: discord.Interaction):
  36.     await interaction.response.send_message(view=DropdownView())
  37.  
  38.  
  39. client.run("TOKEN")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement