first push

This commit is contained in:
Jonathan Jara 2025-04-18 13:59:16 -07:00
commit a1cb90c963
4 changed files with 90 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.env
.venv

70
bot.py Normal file
View File

@ -0,0 +1,70 @@
import os
import requests
import discord
from discord.ext import commands
from discord import app_commands
from dotenv import load_dotenv
import io
import asyncio
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
GUILD_ID = discord.Object(id=1131317261202899034)
JELLYFIN_URL = os.getenv("JELLYFIN_URL")
JELLYFIN_API_KEY = os.getenv("JELLYFIN_API_KEY")
headers= {
"X-Emby-Token": JELLYFIN_API_KEY
}
intents = discord.Intents.default()
intents.message_content = True
intents.voice_states = True
class JellyfinBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="/", intents=intents)
async def setup_hook(self):
self.tree.copy_global_to(guild=GUILD_ID)
await self.tree.sync(guild=GUILD_ID)
bot = JellyfinBot()
@bot.event
async def on_ready():
print(f"🪼 Logged in as {bot.user}")
@bot.tree.command(name="search", description="Search for a song on Jellyfin")
@app_commands.describe(title="Song title to search for")
async def search(interaction: discord.Interaction, title: str):
await interaction.response.defer(ephemeral=True)
url = f"{JELLYFIN_URL}/Items"
params = {
"searchTerm": title,
"Recursive": True,
"IncludeItemTypes": "Audio",
"Limit": 5
}
try:
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
data = response.json()
items = data.get("Items", [])
if not items:
await interaction.followup.send(f"❌ No song found matching `{title}`.")
return
lines = []
for item in items:
title = item.get("Name")
artist = item.get("AlbumArtist", ["Unknown Artist"])
lines.append(f"✅ **{title}** by *{artist}*")
await interaction.followup.send("\n".join(lines))
except requests.RequestException as e:
await interaction.followup.send("⚠️ Failed to contact Jellyfin server.")
print(f"Error: {e}")
bot.run(TOKEN)

BIN
ffmpeg.exe Normal file

Binary file not shown.

18
requirements.txt Normal file
View File

@ -0,0 +1,18 @@
aiohappyeyeballs==2.6.1
aiohttp==3.11.16
aiosignal==1.3.2
attrs==25.3.0
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.4.1
discord.py==2.5.2
frozenlist==1.6.0
idna==3.10
multidict==6.4.3
propcache==0.3.1
pycparser==2.22
PyNaCl==1.5.0
python-dotenv==1.1.0
requests==2.32.3
urllib3==2.4.0
yarl==1.20.0