-
-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7308d08
commit ebb1904
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from functools import partial | ||
from os import getenv | ||
|
||
from dotenv import load_dotenv | ||
|
||
import discord | ||
from discord.ext import commands | ||
|
||
load_dotenv() | ||
|
||
bot = discord.Bot() | ||
|
||
fruits = ["Apple", "Banana", "Orange"] | ||
vegetables = ["Carrot", "Lettuce", "Potato"] | ||
|
||
|
||
async def food_autocomplete( | ||
ctx: discord.AutocompleteContext, food_type: str | ||
) -> list[discord.OptionChoice]: | ||
items = fruits if food_type == "fruit" else vegetables | ||
return [ | ||
discord.OptionChoice(name=item) | ||
for item in items | ||
if ctx.value.lower() in item.lower() | ||
] | ||
|
||
|
||
class FoodCog(commands.Cog): | ||
@commands.slash_command(name="fruit") | ||
async def get_fruit( | ||
self, | ||
ctx: discord.ApplicationContext, | ||
choice: discord.Option( | ||
str, | ||
"Pick a fruit", | ||
autocomplete=partial(food_autocomplete, food_type="fruit"), | ||
), | ||
): | ||
await ctx.respond(f"You picked: {choice}") | ||
|
||
@commands.slash_command(name="vegetable") | ||
async def get_vegetable( | ||
self, | ||
ctx: discord.ApplicationContext, | ||
choice: discord.Option( | ||
str, | ||
"Pick a vegetable", | ||
autocomplete=partial(food_autocomplete, food_type="vegetable"), | ||
), | ||
): | ||
await ctx.respond(f"You picked: {choice}") | ||
|
||
|
||
bot.add_cog(FoodCog()) | ||
bot.run(getenv("TOKEN")) |