Below is the code I am writing The main work is to create a dropdown menu which proceed’s with an option to show all the available commands in the bot.
#MODULES--------------------------------------------------------------------------------------------------------------------------------------------|
import os
import time
import json
import discord
from discord.ui import Select, View
from discord.ext import commands
#GETTING DATA FROM CONFIG FILE----------------------------------------------------------------------------------------------------------------------|
def load_data(file_path):
with open(file_path, 'r') as file:
return json.load(file)
Config_Path = os.path.join(os.path.dirname(__file__), '..', 'Config', 'config.json') # File path.
Config_Data = load_data(Config_Path)
# Loading prefix.
Prefix = Config_Data['PREFIX']
#MAIN-----------------------------------------------------------------------------------------------------------------------------------------------|
class HelpMenu(View):
@discord.ui.select(
placeholder = "Please choose what you need help with",
min_values = 1,
max_values = 1,
options = [
discord.SelectOption(label = 'Command Help', description = 'Show info on all the available commands.', emoji = '🤖', value = 1)
]
)
async def select_callback(self, select, interaction):
select.disabled = True
if select.value[0] == '1':
all_commands = self.bot.commands
embed = discord.Embed(
title = 'Bot Commands',
color = discord.Color.blue()
)
for command in all_commands:
command_name = [f'{Prefix}{command.name}'] + [f'!{alias}' for alias in command.aliases]
aliases_str = ', '.join(command_name[1:]) if len(command_name) > 1 else 'None'
embed.add_field(
name = command_name[0],
value = f'Description: {command.description}\n Aliases: {aliases_str}',
inline = False
)
await interaction.response.edit_message(embed = embed)
class Commands(commands.Cog):
def __init__(self, bot):
self.bot = bot
#(1) Custom help command.
@commands.command(
name = 'help',
aliases = ['Help', 'HELP'],
description = 'Help you to know more about the bot.'
)
async def help(self, ctx):
menu = HelpMenu()
await ctx.reply(view = menu)
#ADDING THE CLASS TO COG'S--------------------------------------------------------------------------------------------------------------------------|
async def setup(bot):
await bot.add_cog(Commands(bot))
The main issue is in the HelpMenu class and in this section
async def select_callback(self, select, interaction):
select.disabled = True
This is the error i am geting
2024-03-02 18:19:54 ERROR discord.ui.view Ignoring exception in view <HelpMenu timeout=180.0 children=1> for item <Select placeholder='Please choose what you need help with' min_values=1 max_values=1 disabled=False options=[<SelectOption label='Command Help' value=1 description='Show info on all the available commands.' emoji=<PartialEmoji animated=False name='🤖' id=None> default=False>]>
Traceback (most recent call last):
File "C:\Users\xesch\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
await item.callback(interaction)
File "c:\Users\xesch\OneDrive\Desktop\Spooks\Cogs\commands.py", line 32, in select_callback
select.disabled = True
^^^^^^^^^^^^^^^
AttributeError: 'Interaction' object has no attribute 'disabled'
I tried finding the solution on chatgpt or youtube but nothing is working.
So I appreciate the help. Thank you.
>Solution :
The arguments in the callback should be the other way around:
async def select_callback(self, interaction, select):
select.disabled = True