`@bot.command()
async def play(ctx, *, query):
try:
if ctx.voice_client is None:
await ctx.send(“I’m not connected to a voice channel.”)
return
# Search for tracks using the Spotify API
results = sp.search(query, limit=1, type='track')
if results['tracks']['items']:
track = results['tracks']['items'][0]
track_id = track['id']
track_url = f"https://open.spotify.com/track/{track_id}"
# Load audio source directly from the Spotify track URL
source = discord.FFmpegPCMAudio(track_url)
# Adjust the volume of the audio source
volume_adjusted_source = discord.PCMVolumeTransformer(source, volume=0.5) # Adjust volume as needed (0.0 to 2.0)
ctx.voice_client.play(volume_adjusted_source)
await ctx.send(f"Now playing: {track['name']} by {', '.join(artist['name'] for artist in track['artists'])}")
else:
await ctx.send("Could not find any matching song.")
except Exception as e:
print(f"Error playing music: {e}")`
it won’t make any sound when joining the voice channel and that is the play func it search for a song, but for some reason it won’t play sound I don’t know if it is the FFpeg doing the problem I have the bot with all permissions