Re: discord bot won't play audio from keybase, but does on local drive

I know the path joining works because the full path of the file is printed to my terminal. I'll provide some code.

#file with path variable is loaded from json.load()
servers["random server"]["current path"]
#let's say it is set to:
"K:\team\pokemon"

@bot.command(help= "play an audio file with the bot")
async def test(ctx, search_string=""):
 #make sure the server name matches what is in the dictionary. If not, update the name before continuing
 server= get_server(ctx.guild.name, ctx.guild.id)
 server["supported files"]= search_system(server["current path"])
 if debug["audio deliver"] or debug["audio all"]:
  lucia.output.speak("Delivered "+str(len(server["supported files"]))+" files.")
 #we copy this list so that the server's supported files doesn't need to be rebuilt constantly
 supported_files= server["supported files"].copy()
 #if the user wants to search for part of a filename, filter the list
 if search_string!="":
  supported_files= filter_result(ctx.guild.name, supported_files, search_string)
 if debug["audio filter"] or debug["audio all"]:
  lucia.output.speak(f"After filter {len(supported_files)} files.")
 #if the supported_files list is empty, it returns a string instead to display to the user
 if type(supported_files)==list:
  filename= random.choice(supported_files)
  if debug["audio file"] or debug["audio all"]:
   lucia.output.speak(filename)
  #we do some processing here, but to cut it short in this example, we will jump directly to the play function
  #we pass the server, the event type, in this case a user requested file, and the full path of the file to play
  await play_audio(ctx.guild, "file", server["current file"]+filename)
 else:
  await ctx.send(supported_files, tts= server["use tts"])

def search_system(start_directory, file_types=["*.wav", "*.mp3", "*.ogg", "*.flac", "*.m4a", "*.wma"]):
 supported_files=[]
 #this recursive function only supports 1 layer of subdirectories which is unfortunate, but not our main concern
 for root, dirnames, filenames in os.walk(start_directory):
  for extensions in file_types:
   for filename in fnmatch.filter(filenames, extensions):
    #this use to have the os.join() function, but that doesn't matter in the end since we are using pathlib.Path
    supported_files.append(f"{root.lower()}\\{filename.lower()}")
 if debug["audio list"] or debug["audio all"]:
  lucia.output.speak("made list")
 return supported_files

def filter_result(server, supported_files, search_string):
 #case sensitive is a bitch, so we make everything lowercase
 search_string= search_string.lower()
 index=0
 while index<len(supported_files):
  if supported_files[index].find(search_string)==-1:
   supported_files.pop(index)
   index-=1
  index+=1
 if debug["audio modify"] or debug["audio all"]:
  lucia.output.speak("modified")
 if len(supported_files)==0:
  #the server has a list of messages it can return if no results were found
  supported_files= random.choice(servers[server]["no files"])
 return supported_files

async def play_audio(server, event, filename):
 this_bot= server.get_member(bot.user.id)
 #try to stop any audio or the new audio won't start
 if server.voice_client.is_playing():
  server.voice_client.stop()
 if this_bot.voice.channel is not None and server.voice_client is not None:
  #this is where it fails
  server.voice_client.play(discord.FFmpegPCMAudio(Path(filename)))

If anyone has any solutions please let me know. Again, if I were to hard code a pth in here, such as
away play_audio(server, event, r"k:\team\pokemon")
that would play the audio file. I have also tried converting the path immediately after the file is chosen instead of when it is time to play the file, but that doesn't make a difference.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : bgt lover via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : defender via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Nuno via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : GrannyCheeseWheel via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Lucas1853 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ivan_soto via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector

Reply via email to