Spotify Twitch Bot

A simple Twitch Bot to handle Spotify Requests

Features

  • Customizable Command Usage
  • Customizable Command Messages
  • Customizable Command Permission (User, Moderator, Broadcaster)
  • En/Disable Commands
  • Async
  • Add Song to Queue via Channel Point Reward
  • Pause Spotify Playback via Command
  • Start Spotify Playback via Command
  • View Current Song via Command (Name, Artist, URL)
  • View Current Playlist via Command (Name, Owner, URL)
  • Skip Song via Command
  • Play previous Song via Command
  • Set Volume via Command
  • Add Song to Queue via Command

Requirements

Setup

Create Spotify Applicaton

Go to your Spotify Developer Dashboard and log into your Account (if you aren´t already).

Click on Create an App.

Enter App Name and Description and accept the ToS and Guidelines.

For this Tutorial we`ll be using the Name Spotify Twitch Bot .

Click on Create.

Click on Show Client Secret.

Make a note of your Client ID and Client Secret in a text document or something similar, you will need them later.

Next click on Edit Settings.

Enter your Redirect URI at Redirect URIs an hit Add (It needs to end with /spotifyCallback).

Make a note of your Redirect URI too.

For this Tutorial we`ll be using http://localhost:8000/spotifyCallback as Redirect URI.

Scroll down a little bit and hit Save.

Create Twitch Application

Go to your Twitch Developer Console and log into your Account (if you aren`t already).

Click on Register Your Application.

As Name we enter Spotify Bot again, but it doesn`t matter what name your application has.

For this Bot, you don`t need a redirect URI at Twitch so we can enter something like https://example.com ad hit *

Add*.

As Category you choose Chat Bot.

Hit Create.

Go to your Applications page again,find the application you just created and click Manage.

At the Bottom you click the button called New Secret.

Make a Note of this Client Secret too.

Generate Twitch Token

A popup with 2 options will appear. You click on Custom Scope Token.

This Bot need the scopes "chat : read", "chat : edit" and "channel : read : redemptions".

Hit Generate Token!.

After Authorizing and completing the captcha, you see three fields with Tokens.

Make Notes of you Access Token and your Client ID.

Setup the Bot

Download the latest Version from Releases.

Unpack all the Files in a new Folder.

Now you need to fill in all the Data, you noticed.

Open the config.ini File and put in the Data you noticed.

Config File
[Spotify]
CLIENT_ID = YOUR_SPOTIFY_CLIENT_ID
CLIENT_SECRET = YOUR_SPOTIFY_CLIENT_SECRET
REDIRECT_URI = YOUR_SPOTIFY_REDIRECT_URI

[Webserver]
PORT = 8000

[Twitch]
CLIENT_ID = YOUR_TWITCH_CLIENT_ID
CLIENT_SECRET = YOUR_TWITCH_CLIENT_SECRET
ACCESS_TOKEN = YOUR_TWITCH_ACCESS_TOKEN
CHANNEL_NAME = YOUR_TWITCH_CHANNEL_NAME

[Reward]
ENABLE_REWARD_SONG_REQUEST = true
REWARD_NAME = YOUR_SONG_REQUEST_REWARD_NAME

If you want to edit any of the Commands, you can edit the commands.json File.

Commands FIle
{
"pause": {
 "usage": "!pause",
 "enabled": true,
 "message": "Playback was paused successfully. @%user%",
 "permission": "MODERATOR"
},
"playlist": {
 "usage": "!playlist",
 "enabled": true,
 "message": "The Playlist %name% from %owner% is currently running. (\"%link%\") @%user%",
 "permission": "EVERYONE"
},
"previous": {
 "usage": "!previous",
 "enabled": true,
 "message": "The previous Song was played successfully. @%user%",
 "permission": "MODERATOR"
},
"queue": {
 "usage": "!queue",
 "enabled": true,
 "message": "The Song was successfully added to the queue. @%user%",
 "permission": "MODERATOR"
},
"skip": {
 "usage": "!skip",
 "enabled": true,
 "message": "The next Song was played successfully. @%user%",
 "permission": "MODERATOR"
},
"song": {
 "usage": "!song",
 "enabled": true,
 "message": "%name% by %artist% is currently running. (\"%link%\") @%user%",
 "permission": "EVERYONE"
},
"start": {
 "usage": "!start",
 "enabled": true,
 "message": "Playback was resumed successfully. @%user%",
 "permission": "MODERATOR"
},
"volume": {
 "usage": "!volume",
 "enabled": true,
 "message": "The volume was successfully set to %volume%. @%user%",
 "permission": "MODERATOR"
}
}

Click your Start File (Windows or Linux) and go to *localhost:

PORT/spotify* The Port is your Port defined in the Config File (default = 8000).

Click the Button called Click here.

Authorize Spotify.

Now you can restart the Bot and you can see if the Access Token got requested.

Finished!

Credits

This Bot is using Twitch4J, Ini4J, Gson, OkHttp and Ktor