Skip to content

Instantly share code, notes, and snippets.

@ariankordi
Created September 14, 2017 00:08
Show Gist options
  • Save ariankordi/e6091366c01ed75dcf107a09c53bb1b1 to your computer and use it in GitHub Desktop.
Save ariankordi/e6091366c01ed75dcf107a09c53bb1b1 to your computer and use it in GitHub Desktop.
discord.py script for me to pipe audio from vgmstream
import os, time, subprocess
import discord
from discord.ext.commands import Bot
main = Bot(command_prefix=("did you get me my CHEEZ WHIZ bo"))
discord.opus.load_opus('/usr/local/Cellar/opus/1.2.1/lib/libopus.dylib')
@main.event
async def on_voice_state_update(b, a):
if not a.voice.voice_channel:
voicechan = b.voice.voice_channel
vm = voicechan.voice_members
if len(vm) == 1:
try:
await voicechan.server.voice_client.disconnect()
except Exception as e:
pass
#await main.send_message(voicechan.server.default_channel, "fuck I couldn't leave\n```" + str(e) + "```")
@main.command(pass_context=True)
async def i(ctx, *args):
if not args:
return await main.say("plays muse\n```did you get me my CHEEZ WHIZ boi [stream file that I have on my desktop]\n```")
chanel = ctx.message.author.voice.voice_channel
if not chanel:
return await main.say("what the fuck you aren't in a voice channel")
if not args:
return await main.say("the fuck do you want me to play")
if args[0] == 'say' or args[0] == 'talk':
args[0] = ''
saystr = " ".join(args)
subprocess.Popen(["say", "--voice=Daniel", saystr], stdout=subprocess.PIPE)
voice = await main.join_voice_channel(chanel)
player = voice.create_ffmpeg_player(filename="out.aiff")
player.start()
if args[0] == 'gtfo' or args[0] == 'leave' or args[0] == 'stop' or args[0] == 'bye':
#chanel.disconnect()
return await main.say("idk how to easily implement that")
try:
voice = await main.join_voice_channel(chanel)
except:
return await main.say("sorry can't stop playing this and play `" + args[0] + "` :frowning2: ")
try:
lla = " ".join(args)
if not "." in lla:
argh = lla + ".wav"
else:
argh = lla
#fstrm = open(argh, 'rb')
fstrm = subprocess.Popen(["vgmstream", "-l 10", "-P", argh], stdout=subprocess.PIPE).stdout
player = voice.create_ffmpeg_player(filename=fstrm, pipe=True, before_options="")
#player = voice.create_stream_player(penis)
player.start()
#fsize = os.fstat(fstrm.fileno()).st_size
#await main.say("licking Splatoon 2 cartridge :tongue::squid: ")
#return await main.say("__**Now Playing:**__ `{0}` at {1} bytes".format(argh, fsize))
return await main.say("*tosses "+ ctx.message.author.name +" a can of Cheez Whiz*")
except Exception as e:
await voice.disconnect()
return await main.say("uhhh\n```" + str(e) + "```")
main.run('token')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment