2020-10-28 11:47:39 +00:00
|
|
|
import discord
|
|
|
|
import datetime
|
2020-11-21 12:55:44 +00:00
|
|
|
import lavalink
|
2020-10-28 11:47:39 +00:00
|
|
|
import os
|
|
|
|
|
2020-11-21 12:55:44 +00:00
|
|
|
from discord.ext import commands
|
|
|
|
|
|
|
|
|
2020-10-28 11:47:39 +00:00
|
|
|
class Music(commands.Cog):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
@commands.command()
|
|
|
|
async def join(self, ctx):
|
|
|
|
vc = ctx.author.voice.channel
|
2020-11-21 12:55:44 +00:00
|
|
|
voiceClient = discord.utils.get(self.bot.voice_clients, guild=ctx.guild)
|
2020-10-28 11:47:39 +00:00
|
|
|
if voiceClient and voiceClient.is_connected():
|
|
|
|
await voiceClient.move_to(vc)
|
|
|
|
print(f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Music] The bot has moved to {vc} in {ctx.guild.name}\n")
|
|
|
|
await ctx.send(f'Joined `{vc.name}`')
|
|
|
|
else:
|
|
|
|
await vc.connect()
|
|
|
|
print(f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Music] The bot has connected to {vc} in {ctx.guild.name}\n")
|
|
|
|
await ctx.send(f'Joined `{vc.name}`')
|
|
|
|
|
|
|
|
@commands.command()
|
|
|
|
async def leave(self, ctx):
|
|
|
|
vc = ctx.author.voice.channel
|
2020-11-21 12:55:44 +00:00
|
|
|
voiceClient = discord.utils.get(self.bot.voice_clients, guild=ctx.guild)
|
2020-10-28 11:47:39 +00:00
|
|
|
|
|
|
|
if voiceClient and voiceClient.is_connected():
|
|
|
|
await voiceClient.disconnect()
|
|
|
|
await ctx.send(f'Left `{vc.name}`')
|
|
|
|
print(f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Music] The bot has disconnected from {vc.name} in {ctx.guild.name}\n")
|
|
|
|
else:
|
2020-11-21 12:55:44 +00:00
|
|
|
await ctx.send(f"{ctx.author.name.mention} you fat retard i'm not connected to a vc")
|
2020-10-28 11:47:39 +00:00
|
|
|
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Music] {ctx.author} failed running: {ctx.message.content} in guild: {ctx.guild.name}')
|
2020-11-21 12:55:44 +00:00
|
|
|
# Not Working
|
|
|
|
@commands.command(aliases=['p', 'pla'])
|
|
|
|
async def play(self, ctx, url):
|
|
|
|
em = discord.Embed
|
|
|
|
em.title = 'Music'
|
|
|
|
song_there = os.path.isfile("song.mp3")
|
|
|
|
try:
|
|
|
|
if song_there:
|
|
|
|
os.remove("song.mp3")
|
|
|
|
print("Removed old song file")
|
|
|
|
except PermissionError:
|
|
|
|
print("Trying to delete song file, but it's being played")
|
|
|
|
em.description = 'Music is currently being played.'
|
|
|
|
em.colour = 0xFF0000
|
|
|
|
await ctx.send(embed=em)
|
|
|
|
return
|
|
|
|
|
|
|
|
voice = discord.utils.get(self.bot.voice_clients, guild=ctx.guild)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for file in os.listdir("./"):
|
|
|
|
if file.endswith(".mp3"):
|
|
|
|
name = file
|
|
|
|
print(f"Renamed File: {file}\n")
|
|
|
|
os.rename(file, "song.mp3")
|
|
|
|
|
|
|
|
voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: print("Song done!"))
|
|
|
|
voice.source = discord.PCMVolumeTransformer(voice.source)
|
|
|
|
voice.source.volume = 0.07
|
|
|
|
|
2020-10-28 11:47:39 +00:00
|
|
|
|
2020-11-21 12:55:44 +00:00
|
|
|
nname = name.rsplit("-", 2)
|
|
|
|
em.description = f"Playing: {nname[0]}"
|
|
|
|
em.colour = 0x00FF00
|
|
|
|
await ctx.send(embed=em)
|
2020-10-28 11:47:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup(bot):
|
2020-10-28 12:25:07 +00:00
|
|
|
bot.add_cog(Music(bot))
|