This commit is contained in:
= 2025-04-06 12:00:40 +07:00
parent a6528634fb
commit 8b96a2078b
2 changed files with 78 additions and 79 deletions

77
commands/voice.py Normal file
View File

@ -0,0 +1,77 @@
import nextcord
from nextcord.ext import commands
import yt_dlp
import os
SquogFinalName: str = None
SquogVideo = {
"verbose": True,
'final_ext': 'mp3',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
}],
"outtmpl": './%(uploader)s_%(title)s.%(ext)s',
"quality": "low"
}
SquogCurrentConnection: nextcord.VoiceClient = None
SquogDownload = yt_dlp.YoutubeDL(SquogVideo)
class Main(commands.Cog):
def __init__(self, bot: commands.Bot):
self.client = bot
@commands.command(description="Join the voice channel.")
async def join(ctx: nextcord.Message):
print("Joining")
if not ctx.guild.voice_client:
if ctx.author.voice:
await ctx.author.voice.channel.connect()
await ctx.reply("Joined.")
else:
await ctx.reply("Can't join as you aren't in any voice channel.")
else:
await ctx.reply("Can't join as i'm already in a voice channel.")
@commands.command(description="Leaves the voice channel.")
async def leave(ctx: nextcord.Message):
print("Leaving")
if ctx.guild.voice_client:
await ctx.guild.voice_client.disconnect(force=True)
await ctx.reply("Left.")
else:
await ctx.reply("Can't leave as i'm not in any voice channel.")
@commands.command(description="Plays music in the voice channel.", usage={"link"})
async def play(ctx: nextcord.Message, link):
global SquogEvilFilename
global SquogFinalName
SquogEvilFilename = None
if not ctx.guild.voice_client:
return await ctx.reply("I'm not in a voice channel.")
if ctx.guild.voice_client.is_playing():
return await ctx.reply("I'm already playing music.")
print(ctx.guild.voice_client.is_connected())
SquogVoiceClient = ctx.guild.voice_client
print(link)
SquogDownload.download(link)
SquogInfo = SquogDownload.extract_info(link, download=False)
SquogFinalName = SquogDownload.prepare_filename(SquogInfo)
SquogLength = SquogFinalName.__len__() - 4
SquogExt = os.path.splitext(SquogFinalName)
print(SquogExt)
SquogLength = SquogFinalName.find(SquogExt[1]) + 1
print(SquogLength)
SquogEvilFilename = f"{SquogFinalName[:SquogLength]}mp3"
SquogVoiceClient.play(nextcord.FFmpegPCMAudio(f"{SquogEvilFilename}"))
@commands.command(description="Stops the music in voice channel")
async def stop(ctx: nextcord.Message):
if not ctx.guild.voice_client:
return await ctx.reply("I'm not in a voice channel.")
if not ctx.guild.voice_client.is_playing():
return await ctx.reply("I'm not playing music.")
SquogCurrentConnection.stop()

80
main.py
View File

@ -1,10 +1,5 @@
import os
import logging
import nextcord import nextcord
import yt_dlp
import subprocess
from nextcord.ext import commands from nextcord.ext import commands
import logging
SquogServer = 1356433463854497944 SquogServer = 1356433463854497944
SquogToken = "MTM1NjU2MTY2MjQyOTM2ODQxMQ.G8aypc.CZBX-x6e4Oad3U5zO0nUgc02d9FDIDSNFybysI" SquogToken = "MTM1NjU2MTY2MjQyOTM2ODQxMQ.G8aypc.CZBX-x6e4Oad3U5zO0nUgc02d9FDIDSNFybysI"
@ -14,27 +9,6 @@ client.remove_command("help")
SquogMod = None SquogMod = None
SquogFinalName: str = None
def SquogFilename(d):
global SquogFinalName
SquogFinalName = d.get('info_dict').get('_filename')
SquogVideo = {
"verbose":True,
"progress_hooks": [SquogFilename],
'final_ext': 'mp3',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
}],
"outtmpl": './%(uploader)s_%(title)s.%(ext)s',
"quality": "low"
}
SquogCurrentConnection: nextcord.VoiceClient = None
SquogDownload = yt_dlp.YoutubeDL(SquogVideo)
# _____ _ # _____ _
# / ____| | | # / ____| | |
# | | ___ _ __ ___ _ __ ___ __ _ _ __ __| |___ # | | ___ _ __ ___ _ __ ___ __ _ _ __ __| |___
@ -54,59 +28,7 @@ async def help(ctx: nextcord.Message):
async def ping(ctx: nextcord.Message): async def ping(ctx: nextcord.Message):
await ctx.reply("Pong!") await ctx.reply("Pong!")
@client.command(description="Join the voice channel.") client.add_cog("Main")
async def join(ctx: nextcord.Message):
print("Joining")
if not ctx.guild.voice_client:
if ctx.author.voice:
global SquogCurrentConnection
SquogCurrentConnection = await ctx.author.voice.channel.connect()
await ctx.reply("Joined.")
else:
await ctx.reply("Can't join as you aren't in any voice channel.")
else:
await ctx.reply("Can't join as i'm already in a voice channel.")
@client.command(description="Leaves the voice channel.")
async def leave(ctx: nextcord.Message):
print("Leaving")
if ctx.guild.voice_client:
await ctx.guild.voice_client.disconnect(force=True)
await ctx.reply("Left.")
else:
await ctx.reply("Can't leave as i'm not in any voice channel.")
@client.command(description="Plays music in the voice channel.", usage={"link"})
async def play(ctx: nextcord.Message, link):
global SquogEvilFilename
global SquogFinalName
SquogEvilFilename = None
if not ctx.guild.voice_client:
return await ctx.reply("I'm not in a voice channel.")
if ctx.guild.voice_client.is_playing():
return await ctx.reply("I'm already playing music.")
print(ctx.guild.voice_client.is_connected())
print(SquogCurrentConnection)
SquogVoiceClient = ctx.guild.voice_client
print(link)
SquogDownload.download(link)
SquogInfo = SquogDownload.extract_info(link, download=False)
SquogFinalName = SquogDownload.prepare_filename(SquogInfo)
SquogLength = SquogFinalName.__len__() - 4
SquogExt = os.path.splitext(SquogFinalName)
print(SquogExt)
SquogLength = SquogFinalName.find(SquogExt[1]) + 1
print(SquogLength)
SquogEvilFilename = f"{SquogFinalName[:SquogLength]}mp3"
SquogVoiceClient.play(nextcord.FFmpegPCMAudio(f"{SquogEvilFilename}"))
@client.command(description="Stops the music in voice channel")
async def stop(ctx: nextcord.Message):
if not ctx.guild.voice_client:
return await ctx.reply("I'm not in a voice channel.")
if not ctx.guild.voice_client.is_playing():
return await ctx.reply("I'm not playing music.")
SquogCurrentConnection.stop()
# ______ _ # ______ _
# | ____| | | # | ____| | |