Compare commits
No commits in common. "60ebd345e7610dcc3134b9e0b150e44965c0e580" and "6c2ce758d67c3c759c4c2ab6400cd88d20859376" have entirely different histories.
60ebd345e7
...
6c2ce758d6
1 changed files with 19 additions and 22 deletions
41
main.py
41
main.py
|
|
@ -9,8 +9,8 @@ intents = discord.Intents.default()
|
|||
intents.message_content = True # Needed to read .play/.stop commands
|
||||
bot = commands.Bot(command_prefix="..", intents=intents)
|
||||
|
||||
# Global variable to hold the current voice clients
|
||||
voice_clients = {}
|
||||
# Global variable to hold the current voice client
|
||||
voice_client = None
|
||||
|
||||
# Sets the default volume to 20%, to make headphone users survive
|
||||
# the volume does not change when the bot is already playing, only new audio
|
||||
|
|
@ -23,30 +23,31 @@ async def on_ready():
|
|||
client_id = application_info.id
|
||||
invite_url = f"https://discord.com/oauth2/authorize?client_id={client_id}&permissions=3145728&scope=bot"
|
||||
|
||||
print(f"itt vagyok gecik ( {bot.user} )")
|
||||
print(f"Invite URL: {invite_url}")
|
||||
|
||||
@bot.command()
|
||||
async def play(ctx, url: str):
|
||||
guild_id = ctx.guild.id
|
||||
global voice_client
|
||||
|
||||
if not ctx.author.voice:
|
||||
await ctx.send("lépjél már be egy kurva csatornába te szerencsétlen fasz")
|
||||
return
|
||||
|
||||
if guild_id not in voice_clients or not voice_clients[guild_id].is_connected():
|
||||
voice_clients[guild_id] = await ctx.author.voice.channel.connect()
|
||||
# Connect to the user's voice channel if not already connected
|
||||
if not voice_client or not voice_client.is_connected():
|
||||
voice_client = await ctx.author.voice.channel.connect()
|
||||
|
||||
vc = voice_clients[guild_id]
|
||||
# Stop any currently playing audio
|
||||
if voice_client.is_playing():
|
||||
voice_client.stop()
|
||||
|
||||
if vc.is_playing():
|
||||
vc.stop()
|
||||
|
||||
try:
|
||||
# Load blocked keywords from file
|
||||
with open("blocked_keywords.txt", "r", encoding="utf-8") as f:
|
||||
blocked_keywords = [line.strip().lower() for line in f if line.strip()]
|
||||
|
||||
# YTDLP options
|
||||
ydl_opts = {
|
||||
"format": "bestaudio/best",
|
||||
"quiet": True,
|
||||
|
|
@ -54,7 +55,6 @@ async def play(ctx, url: str):
|
|||
"default_search": "auto",
|
||||
}
|
||||
|
||||
# Use yt-dlp to extract audio URL and check for blocked keywords
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||
info = ydl.extract_info(url, download=False)
|
||||
title = info["title"].lower()
|
||||
|
|
@ -64,17 +64,15 @@ async def play(ctx, url: str):
|
|||
audio_url = info["url"]
|
||||
print("Audio URL:", audio_url)
|
||||
|
||||
# Set up FFmpeg options with the current volume
|
||||
ffmpeg_options = {
|
||||
"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5 -protocol_whitelist file,http,https,tcp,tls,crypto",
|
||||
"options": f"-vn -af volume={current_volume}"
|
||||
}
|
||||
|
||||
# Play the audio
|
||||
vc.play(
|
||||
voice_client.play(
|
||||
FFmpegPCMAudio(audio_url, **ffmpeg_options),
|
||||
after=lambda e: print(f"Finished playing: {e}")
|
||||
)
|
||||
)
|
||||
await ctx.send(f"most ez a fos szól: {info['title']}")
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -82,15 +80,14 @@ async def play(ctx, url: str):
|
|||
|
||||
@bot.command()
|
||||
async def stop(ctx):
|
||||
guild_id = ctx.guild.id
|
||||
global voice_client
|
||||
|
||||
if guild_id in voice_clients and voice_clients[guild_id].is_playing():
|
||||
voice_clients[guild_id].stop()
|
||||
if voice_client and voice_client.is_playing():
|
||||
voice_client.stop()
|
||||
await ctx.send("hát akkor ne hallgassad basszalak szájba")
|
||||
else:
|
||||
await ctx.send("nem is szól semmi te buzeráns fasz")
|
||||
|
||||
#Does not work in multi-server setup, needs fix
|
||||
@bot.command()
|
||||
async def volume(ctx, vol: float):
|
||||
global current_volume
|
||||
|
|
@ -102,11 +99,11 @@ async def volume(ctx, vol: float):
|
|||
|
||||
@bot.command()
|
||||
async def leave(ctx):
|
||||
guild_id = ctx.guild.id
|
||||
global voice_client
|
||||
|
||||
if guild_id in voice_clients and voice_clients[guild_id].is_connected():
|
||||
await voice_clients[guild_id].disconnect()
|
||||
del voice_clients[guild_id]
|
||||
if voice_client and voice_client.is_connected():
|
||||
await voice_client.disconnect()
|
||||
voice_client = None
|
||||
await ctx.send("akkor csá gecik")
|
||||
else:
|
||||
await ctx.send("nem is vagyok voice channelben basszam ki a szádat")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue