import os import discord import spotipy from spotipy.oauth2 import SpotifyClientCredentials from discord.ext import commands intents = discord.Intents.all() intents.voice_states = True intents.message_content = True # v2 SPOTIFY_CLIENT_ID = "" SPOTIFY_CLIENT_SECRET = "" spotify = spotipy.Spotify( client_credentials_manager=SpotifyClientCredentials( client_id=SPOTIFY_CLIENT_ID, client_secret=SPOTIFY_CLIENT_SECRET ) ) bot = commands.Bot(command_prefix="!", intents=intents) @bot.event async def on_ready(): print(f"Logged in as {bot.user.name}") @bot.command() async def join(ctx): voice_channel = ctx.author.voice.channel if not voice_channel: await ctx.send("You need to be in a voice channel to use this command.") return voice_client = discord.utils.get(bot.voice_clients, guild=ctx.guild) if voice_client is None: voice_client = await voice_channel.connect() else: await voice_client.move_to(voice_channel) await ctx.send(f"Joined the voice channel: {voice_channel.name}") @bot.command() async def play(ctx, *, query): voice_client = ctx.voice_client if voice_client is None: await ctx.send("I'm not connected to a voice channel. Use `!join` to make me join a voice channel.") return track_results = spotify.search(q=query, type="track", limit=1) if track_results["tracks"]["items"]: track = track_results["tracks"]["items"][0] track_url = track["external_urls"]["spotify"] voice_client.stop() voice_client.play(discord.FFmpegPCMAudio(track_url)) await ctx.send(f"Now playing: {track['name']}") else: await ctx.send("No track found.") @bot.command() async def pause(ctx): voice_client = ctx.voice_client if voice_client and voice_client.is_playing(): voice_client.pause() await ctx.send("Playback paused.") @bot.command() async def skip(ctx): voice_client = ctx.voice_client if voice_client and voice_client.is_playing(): voice_client.stop() await ctx.send("Skipped to the next track.") @bot.command() async def filter(ctx, filter_type): voice_client = ctx.voice_client if voice_client and voice_client.is_playing(): if filter_type == "bassboost": # Apply bass boost filter pass elif filter_type == "trebleboost": # Apply treble boost filter pass # Add more filters as needed @bot.command() async def leave(ctx): voice_client = ctx.voice_client if voice_client: await voice_client.disconnect() await ctx.send("Left the voice channel.") @bot.event async def on_command_error(ctx, error): if isinstance(error, commands.CommandNotFound): await ctx.send("Invalid command.") bot.run("")