From 140093b405817188c4285188ff84cc0a855fcd36 Mon Sep 17 00:00:00 2001 From: tavo-wasd Date: Sat, 30 Mar 2024 21:47:48 -0600 Subject: [PATCH] init commit --- main.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..25430b6 --- /dev/null +++ b/main.py @@ -0,0 +1,55 @@ +import discord +from discord.ext import commands +import asyncio +import os +from fuzzywuzzy import process + +intents = discord.Intents.default() +intents.message_content = True +intents.voice_states = True + +bot = commands.Bot(command_prefix='!', intents=intents) + +def find_song(query): + # Define the base directory + base_dir = "songs/" + + # Initialize variables to store the best match and confidence + best_match = None + best_confidence = 0 + + # Recursively search through directories for song files + for root, dirs, files in os.walk(base_dir): + for file in files: + if file.endswith(".mp3"): + song_path = os.path.join(root, file) + song_name = os.path.splitext(file)[0] # Get the song name without extension + confidence = process.extractOne(query, [song_name])[1] + + # Update best match if confidence is higher + if confidence > best_confidence: + best_match = song_path + best_confidence = confidence + + return best_match, best_confidence + +@bot.command() +async def play(ctx, *, query): + voice_channel = ctx.author.voice.channel + if voice_channel: + voice_client = await voice_channel.connect() + + # Find the closest match to the query + song_path, confidence = find_song(query) + + if confidence >= 70: # Adjust confidence threshold as needed + voice_client.play(discord.FFmpegPCMAudio(song_path)) + while voice_client.is_playing(): + await asyncio.sleep(1) + await voice_client.disconnect() + else: + await ctx.send("Sorry, couldn't find a match for that song.") + else: + await ctx.send("You need to be in a voice channel to use this command!") + +bot.run('TOKEN')