I'm trying to make a play command on spotipy, I enter everything as it should there is an ID client and a secret from the spotify developer portal.
Here is my code to run:
import disnake
from disnake.ext import commands
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import lavalink
actual_user_id = "your_actual_user_id_goes_here"
class Play(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.spotipy = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id='', client_secret=''))
self.lavalink = lavalink.Client(user_id=actual_user_id)
self.lavalink.add_node('localhost', 2333, 'youshallnotpass', 'eu', 'default')
async def cog_before_invoke(self, ctx):
if ctx.author.voice is None:
embed = disnake.Embed(title='Play', description='First I have to be in the voice channel. Write /join.')
await ctx.send(embed=embed)
raise commands.CommandError("User not in a voice channel")
@commands.slash_command()
async def play(self, ctx, *, track_name):
results = self.spotipy.search(q=track_name, type='track', limit=1)
if results['tracks']['items']:
track = results['tracks']['items'][0]
track_embed = disnake.Embed(
title=track['name'],
description=track['artists'][0]['name'],
color=disnake.Color.blurple()
)
track_embed.set_image(url=track['album']['images'][0]['url'])
# Track playback using lavalink
# code for playing the track using lavalink
await ctx.send(embed=track_embed)
else:
embed = disnake.Embed(title='Play', description='Sorry, I didn't find you track.')
await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(Play(bot))```
If I have indicated something wrong, I ask for help, I want to make a music bot.