101 lines
No EOL
3.2 KiB
Python
101 lines
No EOL
3.2 KiB
Python
import discord
|
|
from discord.ext import commands
|
|
from discord import FFmpegPCMAudio
|
|
|
|
import yt_dlp
|
|
|
|
# Set up intents and bot
|
|
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 client
|
|
voice_client = None
|
|
|
|
@bot.event
|
|
async def on_ready():
|
|
# Construct the invite URL dynamically
|
|
application_info = await bot.application_info()
|
|
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):
|
|
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
|
|
|
|
# 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()
|
|
|
|
# Stop any currently playing audio
|
|
if voice_client.is_playing():
|
|
voice_client.stop()
|
|
|
|
|
|
# Stream audio from YouTube
|
|
try:
|
|
# yt-dlp options
|
|
ydl_opts = {
|
|
"format": "bestaudio", # Prefer Opus with at least 160 kbps
|
|
"quiet": True,
|
|
"default_search": "ytsearch", # <--- This is the key fix
|
|
}
|
|
|
|
|
|
|
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
info = ydl.extract_info(url, download=False)
|
|
title = info["title"].lower()
|
|
|
|
blocked_keywords = [
|
|
"roma", "cigány", "mulatós", "azahriah", "azariah", "majka", "gypsy", "zgstudio", "curtis", "gipsy", "karpatia", "kárpátia",
|
|
"tóth gabi", "jolly", "dögös robi", "sandu ciorba", "maco mamuko", "ismerős arcok", "nicolae guta", "egészséges fejbőr", "puzsér"
|
|
]
|
|
if any(keyword in title for keyword in blocked_keywords):
|
|
await ctx.send(f"na ezt a fost nem jatszom le: `{info['title']}`")
|
|
return
|
|
|
|
audio_url = info["url"]
|
|
|
|
ffmpeg_options = {
|
|
"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5",
|
|
"options": "-vn"
|
|
}
|
|
|
|
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:
|
|
await ctx.send(f"most ezzel mi a kurva anyámat kezdjek?: {e}")
|
|
|
|
@bot.command()
|
|
async def stop(ctx):
|
|
global voice_client
|
|
|
|
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")
|
|
|
|
@bot.command()
|
|
async def leave(ctx):
|
|
global voice_client
|
|
|
|
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")
|
|
|
|
# Run the bot
|
|
TOKEN = open("TOKEN").read().strip()
|
|
bot.run(TOKEN) |