from typing import List import disnake from disnake import Option, OptionType, OptionChoice from disnake.ext import commands from lib import list_files from lib import logger from lib import play_audio class Testing(commands.Cog, name='Testing'): def __init__(self, bot): self.bot = bot # defining bot as global var in class @commands.Cog.listener() # this is a decorator for events/listeners async def on_ready(self): logger.info(f'Cog {__name__.split(".")[1]} is ready!.') @commands.slash_command(name="play_audio", options=[ Option(name="audio", type=OptionType.string, required=True # choices=OptionChoice(list_to_play) ) ]) async def playaudio(self, inter: disnake.ApplicationCommandInteraction, audio: str ): if inter.author.voice is not None: await inter.response.send_message(f'Played {audio}') await play_audio(audio, self.bot, inter.author.voice.channel) else: await inter.response.send_message('You`re not in voice') @playaudio.autocomplete('audio') async def list_to_play(self, inter: disnake.ApplicationCommandInteraction, current: str) -> List[OptionChoice]: def_list = await list_files() try: user_list = await list_files(str(inter.author.id)) # user_dict = [] # for _track in user_list: except IndexError: user_list = [] _list = def_list + user_list return [ OptionChoice(name=choice, value=choice) for choice in def_list if current.lower() in choice.lower() ] def setup(bot): # an extension must have a setup function bot.add_cog(Testing(bot)) # adding a cog