Here's my current Play command, I know there is an issue with it checking if its in the right voice channel, but I can probably figure that out eventually, what I'm worried about is that I'm pretty sure this code won't work if people are trying to play music at the same time in different servers.
@bot.command(name='play', help='This command plays songs')
async def play(ctx, *args):
searchterm = " ".join(args)
print(searchterm)
global queue
if not ctx.message.author.voice:
await ctx.send("You are not connected to a voice channel")
return
else:
channel = ctx.message.author.voice.channel
botchannel = ctx.bot.voice_clients
print(channel)
print(botchannel)
await channel.connect()
if 'youtube.com' in searchterm:
queue.append(searchterm)
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
player = await YTDLSource.from_url(queue[0], loop=bot.loop)
voice_channel.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send('**Now playing:** {}'.format(player.title))
del(queue[0])
elif 'youtube.com' not in searchterm:
results = SearchVideos(searchterm, offset=1, mode = "dict", max_results=1).result()
resultlist = results['search_result']
resultdict = resultlist[0]
url = resultdict['link']
queue.append(url)
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
player = await YTDLSource.from_url(queue[0], loop=bot.loop)
voice_channel.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send('**Now playing:** {}'.format(player.title))
del(queue[0])