V1.0 working version
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import discord
|
||||
|
||||
__version__ = "1.0.0"
|
||||
__author__ = "Kartoniarz"
|
||||
|
||||
|
||||
class Bot(discord.Bot):
|
||||
def __init__(self):
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.members = True
|
||||
|
||||
super().__init__(intents=intents)
|
||||
|
||||
async def on_ready(self):
|
||||
print(f"Zalogowano jako {self.user} (ID: {self.user.id})")
|
||||
print(f" Pycord {discord.__version__} | Bot v{__version__}")
|
||||
@@ -0,0 +1,7 @@
|
||||
import os
|
||||
|
||||
def setup(bot):
|
||||
for filename in os.listdir(os.path.dirname(__file__)):
|
||||
if filename.endswith(".py") and not filename.startswith("_"):
|
||||
bot.load_extension(f"bot.cogs.{filename[:-3]}")
|
||||
print(f"Załadowano: {filename[:-3]}")
|
||||
@@ -0,0 +1,19 @@
|
||||
import discord
|
||||
from ..utils import helpers
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
class Simp(commands.Cog):
|
||||
def __init__(self, bot: discord.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@discord.slash_command(description="Nie, nie jestem pantoflem")
|
||||
async def pantofel(self, ctx: discord.ApplicationContext, url: str):
|
||||
await ctx.defer()
|
||||
|
||||
filename = helpers.download_video(url)
|
||||
await ctx.respond(file=discord.File(filename))
|
||||
|
||||
|
||||
def setup(bot: discord.Bot):
|
||||
bot.add_cog(Simp(bot))
|
||||
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
import yt_dlp
|
||||
|
||||
|
||||
def download_video(yt_url: str) -> str:
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
DOWNLOADS = os.path.join(BASE_DIR, "downloads")
|
||||
|
||||
ydl_opts = {
|
||||
'format': 'bestvideo+bestaudio/best',
|
||||
'merge_output_format': 'mp4',
|
||||
'outtmpl': f'{DOWNLOADS}/%(title)s.%(ext)s',
|
||||
}
|
||||
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||
os.makedirs(DOWNLOADS, exist_ok=True)
|
||||
info = ydl.extract_info(yt_url, download=True)
|
||||
filename = ydl.prepare_filename(info)
|
||||
|
||||
return filename
|
||||
Reference in New Issue
Block a user