import discord
from discord.ext import commands
class Dropdown(discord.ui.Select):
def __init__(self):
options = [
discord.SelectOption(label='Red', description='Your favourite colour is red', emoji=''),
discord.SelectOption(label='Green', description='Your favourite colour is green', emoji=''),
discord.SelectOption(label='Blue', description='Your favourite colour is blue', emoji=''),
]
super().__init__(placeholder='Choose your favourite colour...', min_values=1, max_values=1, options=options)
async def callback(self, interaction: discord.Interaction):
await interaction.response.send_message(f'Your favourite colour is {self.values[0]}')
class DropdownView(discord.ui.View):
def __init__(self):
super().__init__()
self.add_item(Dropdown())
class Bot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__(command_prefix=commands.when_mentioned_or('$'), intents=intents)
async def on_ready(self):
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
bot = Bot()
@bot.command()
async def colour(ctx):
view = DropdownView()
await ctx.send('Pick your favourite colour:', view=view)
bot.run('token')