import listen import discord from discord.ext import commands import websockets import json import time import asyncio b = "" class listen:  """Beta. Please don't run yet.""" def __init__(self, bot): self.bot = bot async def whiile(websocket, ctx, timee): time.sleep(timee/1000) await websocket.send('{ "op": 9 }') c = json.loads(await websocket.recv()) c = json.loads(await websocket.recv()) if c["op"] == 1: await ctx.send("Currently playing: " + c["d"]["song"]["title"]) @commands.command() async def listen_moe(self, ctx): # if ctx.message.author.voice.is_connected() == True: # await ctx.message.author.voice.disconnect() if ctx.message.author.voice == None: await ctx.send("I'm only going to play listen.moe if you're there to listen with me. ;-;") else: a = await ctx.message.author.voice.channel.connect() a.play(discord.FFmpegPCMAudio("https://listen.moe/stream")) async with websockets.connect("wss://listen.moe/gateway") as web: await web.send('{ "op": 0, "d": {"auth": "" } }') b = json.loads(await web.recv()) c = json.loads(await web.recv()) await ctx.send("Joined Listen.moe! Currently playing: " + c["d"]["song"]["title"]) lsock = listen.whiile(web, ctx, b["d"]["heartbeat"]) asyncio.get_event_loop().run_until_complete(lsock) asyncio.get_event_loop().run_forever() @commands.command() async def stop(self, ctx): if ctx.voice_client: ctx.voice_client.source.cleanup() await ctx.voice_client.disconnect() def setup(bot): bot.add_cog(listen(bot))