π‘How does it work?
@commands.hybrid_command(
name="rulebook", description="Load an Interactive LastFish! Rulebook and Guide!"
)
async def rulebook(self, ctx):
"""An interactive rulebook and guide!"""
# Creates DropDown menu + Options
class Dropdown(discord.ui.Select):
def __init__(self):
options = [
discord.SelectOption(label=Key Name, Description=whatever you want
]
super().__init__(
placeholder="Please Select a Page",
min_values=1,
max_values=1,
options=options,
)
# Gets user Selected option and returns it as an Embed
async def callback(self, interaction: discord.Interaction):
selected_option = self.values[0]
information = rulebook_pages[selected_option]["information"]
for option in self.options:
if option.label == selected_option:
embed = discord.Embed(
title=option.label,
description=option.description,
color=6750182,
)
embed.add_field(name="", value=information)
embed.set_image(
url=rulebook_pages.get(option.label, {}).get("image", None)
)
await interaction.response.send_message(embed=embed, ephemeral=True)
#Discord Dropdown Shenanigans
class DropdownView(discord.ui.View):
def __init__(self):
super().__init__()
# Adds the dropdown to our view object.
self.add_item(
Dropdown(),
)
logger.info("Command Invoked")
# Creates and Sends Beginning Embed from /rulebook command
welcome_embed = discord.Embed(
# Formatting Welcome Embed.
view = DropdownView()
message = await ctx.send(embed=welcome_embed, view=view, ephemeral=True)
await asyncio.sleep(180)
await message.delete()
logger.info("Welcome Embed Deleted")Code Explanation
The code above allows for the use of / commands and text based commands by the hybrid decorator (the @hybrid_commands.command) it then sends a "Welcome" embed and adds a drop down menu with the possible selections based off of a key pair in a dictionary! The key pairs in the dictionary are then pre-filled with the information from the rulebook and populated onto a new embed and sent to the user!
Last updated