I am working on a discord bot and returning a list of item. Unfortunately, if the list exceeds 25 items, it throws an error. I want break the loop after 25 loops. Below is a sample of code provided in the discord.py documentation; the for loop is a single line and does not work if I try to modify it:
async def fruit_autocomplete(
interaction: discord.Interaction,
current: str,
) -> List[app_commands.Choice[str]]:
fruits = ['Banana', 'Pineapple', 'Apple', 'Watermelon', 'Melon', 'Cherry']
return [
app_commands.Choice(name=fruit, value=fruit)
for fruit in fruits if current.lower() in fruit.lower()
]