diff --git a/config/__pycache__/config.cpython-310.pyc b/config/__pycache__/config.cpython-310.pyc index 4c249b2..ab975de 100644 Binary files a/config/__pycache__/config.cpython-310.pyc and b/config/__pycache__/config.cpython-310.pyc differ diff --git a/config/config.py b/config/config.py index db280a7..b8c4105 100644 --- a/config/config.py +++ b/config/config.py @@ -1,9 +1,10 @@ import discord bot_token = 'MTIzMjE3NTYwNzU2NDIxMDIxNw.GEp7Ge.HPvDBvgPN97jVMKl-jTm9YgM3W4OkkEBP5Efgc' - +serversettings = 'serversettings.json' ffmpeg_options = { 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', + # 'options': '-vn -filter:a "volume=0.5"', 'options': '-vn', } @@ -20,7 +21,7 @@ 'source_address': '0.0.0.0', 'force-ipv4': True, 'preferredcodec': 'mp3', - 'cachedir': False + 'cachedir': False, } diff --git a/config/serversettings.json b/config/serversettings.json new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py index 8bc4e17..642ab31 100644 --- a/main.py +++ b/main.py @@ -16,10 +16,12 @@ queue = [] + @bot.event async def on_ready(): - print(f'Logged in as {bot.user}') + print(f'Successfully booted: {bot.user}') await bot.change_presence(activity=discord.Game(name="!play ", ), status=discord.Status.do_not_disturb) + @@ -46,11 +48,19 @@ async def play(ctx, *, query: str): video_url = info['url'] + ctx.bot.video_info = info + ctx.bot.video_url = video_url # Play the audio using FFmpeg audio_source = discord.FFmpegPCMAudio(video_url, executable=FFMPEG_PATH, **config.ffmpeg_options) + audio_source = discord.PCMVolumeTransformer(audio_source, volume=0.5) voice_client.play(audio_source) await ctx.send(f":notes: Now playing: {info['title']} from {info['original_url']}") + # disconnect when the song is over but not when pausing + while voice_client.is_connected() and (voice_client.is_playing() or ctx.voice_client.is_paused()): + await asyncio.sleep(1) + await stop(ctx) + except Exception as e: print(f"Error playing music: {e}") @@ -60,6 +70,7 @@ async def play(ctx, *, query: str): async def stop(ctx): if ctx.voice_client and ctx.voice_client.is_connected(): await ctx.voice_client.disconnect() + await ctx.send("Music stopped.") @bot.command(name='pause', help='Pause the currently playing music') async def pause(ctx): @@ -70,11 +81,51 @@ async def pause(ctx): ctx.voice_client.resume() await ctx.send("Music resumed.") +@bot.command(name='volume', help='Adjust the volume level.') +async def volume(ctx, volume: float): + # Ensure the input volume is a percentage (e.g., 50 for 50%) + volume = volume / 100 # Convert to a float from a percentage + + if ctx.voice_client and ctx.voice_client.is_playing(): + # Re-create the audio source with the new volume + if bot.original_source is None: + bot.original_source = ctx.voice_client.source # Original audio source + new_source = discord.PCMVolumeTransformer(bot.original_source, volume=volume) # Create a new volume transformer + + # Stop current playback + ctx.voice_client.source = new_source + + + await ctx.send(f"Volume set to {volume * 100}%.") + else: + await ctx.send("No music is currently playing.") @bot.command(name='ping', help='Check the bot\'s latency') async def ping(ctx): await ctx.send(f'Pong! Latency: {round(bot.latency * 1000)}ms, websocket latency: {round(bot.ws.latency * 1000)}ms') +@bot.command(name='seek', help='Set the playback position to a specific time in seconds') +async def fastforward(ctx, seconds: int): + # Ensure there is a voice client playing music + if ctx.voice_client and ctx.voice_client.is_playing(): + # Stop the current playback + ctx.voice_client.stop() + + # Check if there's stored video information + if hasattr(ctx.bot, 'video_info') and hasattr(ctx.bot, 'video_url'): + # Add the offset in seconds to the FFmpeg options to fast forward + seek_time = f"-ss {seconds}" + ffmpeg_opts = {**config.ffmpeg_options, "options": f"{config.ffmpeg_options['options']} {seek_time}"} + + audio_source = discord.FFmpegPCMAudio(ctx.bot.video_url, executable=FFMPEG_PATH, **ffmpeg_opts) + + ctx.voice_client.play(audio_source) + + await ctx.send(f"Started playing at {seconds} seconds.") + else: + await ctx.send("No music data available to seek.") + else: + await ctx.send("No music is currently playing.") @bot.event async def on_message(message): diff --git a/requirements.txt b/requirements.txt index 1385a6b..237f475 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ PyNaCl discord yt_dlp -ffmpeg \ No newline at end of file +ffmpeg +json \ No newline at end of file