I m trying to create a command in my Discord bot using discord.py where I want to use both buttons and dropdowns (select menus) together, similar to the help command in Dank Memer bot. I have created separate classes for buttons (Buttons) and select menus (categorySelect), and they work fine individually. However, when I try to use both of them together in a single command, I m facing an issue.
I have tried putting both the Buttons and categorySelect instances into a list and passing it to the View class, but it didn t work as expected
class Buttons(discord.ui.View):
def __init__(self, *, timeout=15):
super().__init__(timeout=timeout)
self.timeout = timeout
self.click = False
@discord.ui.button(label="Rock?",style=discord.ButtonStyle.green, custom_id="easy") # or .primary
async def rock_button(self,interaction:discord.Interaction,child:discord.ui.Button):
for child in self.children:
child.disabled=True
win_embed = discord.Embed(title="You win ?!",description="**Your Choice:** Rock?
**Xynox Choice:** Scissors✂️",color=discord.Color.green())
loss_embed = discord.Embed(title="You lose ?!",description="**Your Choice:** Rock?
**Xynox Choice:** Paper?",color=discord.Color.red())
tie_embed = discord.Embed(title="It s a tie ?!",description="**Your Choice:** Rock?
**Xynox Choice:** Rock?",color=discord.Color.blurple())
embed = random.choice([win_embed, loss_embed, tie_embed])
await interaction.response.edit_message(embed=embed, view=self)
class categorySelect(View):
@discord.ui.select(
placeholder= Select a category ,
options=[
discord.SelectOption(label= Guns , value = "1", description= Dangerous Guns stolen from the government , emoji= <:golden_sniper:1123954953640218724> ),
discord.SelectOption(label= Drugs , value = "2", description= Drugs that can be used to get high , emoji= <:weed:1124062866505486356> ),
discord.SelectOption(label= Swords , value = "3", description= The Ancient Blades of Death , emoji= ⚔️ ),
# discord.SelectOption(label= Go Back , value = "3", description= Go Back!!! , emoji= ↩️ ),
]
)
async def select_option_callback(self, interaction, select):
if select.values[0] == "1":
snack_embed = discord.Embed(title= Guns , description= Reload em , color=discord.Color.random())
await interaction.response.edit_message(embed=snack_embed, view=categorySelect())
elif select.values[0] == "2":
snack_embed = discord.Embed(title= Drugs , description= Get High , color=discord.Color.random())
await interaction.response.edit_message(embed=snack_embed, view=categorySelect())
class help(commands.Cog):
def __init__(self, client):
self.client = client
@app_commands.command(name= help , description= Gives info about all the commands )
async def help(self, interaction: discord.Interaction):
embed = discord.Embed(title="Help", description="Use the dropdown to select a category", color=discord.Color.random())
category = categorySelect()
button = Buttons()
cl = [category, button]
#use both of these together
await interaction.response.send_message(embed=embed, view=cl)```