Skip to content

Instantly share code, notes, and snippets.

@return0927
Last active September 12, 2020 11:47
Show Gist options
  • Save return0927/63ab21c2bd572c76b7fe6ddda631b495 to your computer and use it in GitHub Desktop.
Save return0927/63ab21c2bd572c76b7fe6ddda631b495 to your computer and use it in GitHub Desktop.
discord.py==1.0.3
import discord
from discord.ext import commands
import constants
import asyncio
import traceback
if not discord.opus.is_loaded():
discord.opus.load_opus("libopus-0.dll")
client = commands.Bot("ENAK;;")
@client.event
async def on_ready():
print(" [!] Bot Ready with {}({})".format(client.user.name, client.user.id))
@client.event
async def on_message(msg):
if not msg.author.id in constants.allow:
return
if not msg.content.startswith("ENAK;;"):
return
command, *args = msg.content[6:].split(" ")
# > Debug or arg parsing
# await msg.channel.send(msg.author.mention + " Command: {}, Args: {}".format(command, ", ".join(args)))
# Summon onto voice chat
if command == "join" or command == "summon":
feedback = await msg.channel.send(msg.author.mention + " Joining")
summon_channel = None
for channel in msg.guild.voice_channels:
if msg.author in channel.members:
summon_channel = channel
break
if not summon_channel:
await feedback.edit(content=msg.author.mention + " No joinable voice channel. Please join one and try again.")
return
await feedback.edit(content=msg.author.mention + " Joining {0.name}(#{0.id})".format(summon_channel))
try:
voice_client = await summon_channel.connect()
await feedback.edit(content=msg.author.mention + " Joined {0.name}(#{0.id})".format(summon_channel))
except:
await feedback.edit(
content=msg.author.mention + " Error on joining {0.name}(#{0.id})\n```\n{1}\n```".format(summon_channel, traceback.format_exc())
)
if command == "playtest":
feedback = await msg.channel.send(msg.author.mention + " Playing")
voice_client = None
for _client in client.voice_clients:
if _client.guild.id == msg.guild.id:
voice_client = _client
break
if not voice_client:
await feedback.edit(content=msg.author.mention + " No playable client. Please summon first")
return
try:
target = "avicii"
if args:
target = args[0] + ".mp4"
print(discord.opus.is_loaded())
player = discord.PCMVolumeTransformer(
discord.FFmpegPCMAudio(
r"C:\Users\bjleh\PycharmProjects\DiscordMusic\{}".format(target),
# before_options="-nostdin",
options="-vn -b:a 192k",
)
)
voice_client.play(player)
# voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
while voice_client.is_playing():
await asyncio.sleep(1)
voice_client.stop()
await voice_client.disconnect()
await feedback.edit(content=msg.author.mention + " End")
except:
print(traceback.format_exc())
await feedback.edit(content=msg.author.mention + " Error on playing, \n```{}\n```".format(traceback.format_exc()))
client.run(constants.token)
@0xfmc
Copy link

0xfmc commented Feb 22, 2020

굳!!!

Copy link

ghost commented Sep 12, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment