"Python script to get notified of a random music to listen to, on Discord, using Spotify API and Discord Webhook."
-
Open your Discord server.
-
Go to Server Settings > Integrations > Webhooks.
-
Click "New Webhook" and customize it as you like.
-
Copy the Webhook URL.
-
Create a Spotify Developer Account:
-
Go to the Spotify Developer Dashboard and log in with your Spotify account. Create a New Spotify App:
-
Click "Create an App" and fill in the required fields (App name, App description, etc)
-
After creating the app, you'll receive a "Client ID" and "Client Secret." Save these credentials.
- Use the Spotify Web API Console or the Authorization Code Flow to get an access token.
- For simplicity, you can manually obtain a token via the Web API Console:
- Go to the Spotify Web API Console. Log in with your Spotify account and click "Get Token" to authorize and get an access token.
curl -X POST "https://accounts.spotify.com/api/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&client_id=your-client-id&client_secret=your-client-secret"
- replace the client_id and client_secret before sending the request to get your access token
- Install required libraries
pip install requests
-
copy the python script and make a new python file
song-notifier.py
-
Replace Placeholder Values
Open the
song-notifier.py
file and replaceclient_id
,client_secret
,access_token
andYOUR_DISCORD_WEBHOOK_URL
-
you can always modify the genre e.g
metal,rock,pop,rap,country e.t.c
, to get recommended, genre specified songs
- You can use Google Console , AWS or Heroku e.t.c
- "Instead, you choose to run it locally, create a cron job so that it can automatically run at specified intervals of time."
crontab -e
0 */8 * * * /usr/bin/python /home/samsep10l/Desktop/song-notifier.py
- to list cron jobs
crontab -l