In my discord.py bot, I am trying to make a function that runs the code that's nescessary for the bot to join a voice channel, play an audio file, and then leave. I am doing this, so I do not have to copy and paste the same code for every voice command that I want to make. However, I cannot get the function to run.
I have tried playing around with async def and await functions for my function, however it does not seem to work. I am clueless, as when I run my code, I receive no errors.
async def voiceCommand(ctx, message, file, time, cmd):
channel = ctx.message.author.voice.voice_channel
if channel == None: # If the user who sent the voice command isn't in a voice channel.
await client.say('You are not in a voice channel, therefore I cannot run this command.')
return
else: # If the user is in a voice channel
print(executed(cmd, message.author))
voice = await client.join_voice_channel(channel)
server = ctx.message.server
voice_client = client.voice_client_in(server)
player = voice.create_ffmpeg_player(file) # Uses ffmpeg to create a player, however it makes a pop up when it runs.
player.start()
time.sleep(float(time))
await voice_client.disconnect() # Disconnects WingBot from the voice channel.
and
@client.command(pass_context = True)
async def bigbruh(ctx):
voiceCommand(ctx, message, 'bigbruh.mp3', '0.5', 'bigbruh')
These are the snippets of code I am trying to use to run the function.
Full source code here: https://pastebin.com/bv86jSvk