feat: Enhance autocomplete for role category names to include all options when input is empty
This commit is contained in:
parent
d73efb9735
commit
478b6709d3
@ -364,28 +364,25 @@ class RoleSelectorCog(commands.Cog):
|
||||
return config
|
||||
return None
|
||||
|
||||
@roleselect_group.command(name="addcategory", description="Adds a new role category for selection.")
|
||||
@app_commands.checks.has_permissions(manage_guild=True)
|
||||
@app_commands.describe(
|
||||
name="The name for the new category.",
|
||||
description="A description for this role category.",
|
||||
max_selectable="Maximum number of roles a user can select from this category (default: 1).",
|
||||
preset_id="Optional ID of a global preset to base this category on."
|
||||
)
|
||||
async def autocomplete_category_name(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
|
||||
choices = []
|
||||
# Add existing guild category names
|
||||
if interaction.guild:
|
||||
guild_configs = db.get_guild_role_category_configs(str(interaction.guild_id))
|
||||
for config in guild_configs:
|
||||
if config.name.lower().startswith(current.lower()):
|
||||
if config.name.lower().startswith(current.lower()): # Check if current is not empty before startswith
|
||||
choices.append(app_commands.Choice(name=config.name, value=config.name))
|
||||
|
||||
elif not current: # If current is empty, add all
|
||||
choices.append(app_commands.Choice(name=config.name, value=config.name))
|
||||
|
||||
# Add global preset names
|
||||
presets = db.get_all_role_category_presets()
|
||||
for preset in presets:
|
||||
if preset.name.lower().startswith(current.lower()):
|
||||
choices.append(app_commands.Choice(name=f"Preset: {preset.name}", value=preset.name)) # Use preset name as value
|
||||
if preset.name.lower().startswith(current.lower()): # Check if current is not empty
|
||||
choices.append(app_commands.Choice(name=f"Preset: {preset.name}", value=preset.name))
|
||||
elif not current: # If current is empty, add all
|
||||
choices.append(app_commands.Choice(name=f"Preset: {preset.name}", value=preset.name))
|
||||
|
||||
|
||||
# Limit to 25 choices as per Discord API limits
|
||||
return choices[:25]
|
||||
@ -393,10 +390,10 @@ class RoleSelectorCog(commands.Cog):
|
||||
@roleselect_group.command(name="addcategory", description="Adds a new role category for selection.")
|
||||
@app_commands.checks.has_permissions(manage_guild=True)
|
||||
@app_commands.describe(
|
||||
name="The name for the new category.",
|
||||
name="The name for the new category (or select a preset).",
|
||||
description="A description for this role category.",
|
||||
max_selectable="Maximum number of roles a user can select from this category (default: 1).",
|
||||
preset_id="Optional ID of a global preset to base this category on."
|
||||
preset_id="Optional ID of a global preset to base this category on (auto-filled if preset selected for name)."
|
||||
)
|
||||
@app_commands.autocomplete(name=autocomplete_category_name)
|
||||
async def roleselect_addcategory(self, interaction: discord.Interaction, name: str, description: str, max_selectable: Optional[int] = 1, preset_id: Optional[str] = None):
|
||||
|
Loading…
x
Reference in New Issue
Block a user