How to add the !song command to the chat bot


#1

Hi. I want to add the !song command to the chat bot I wrote. I found a video but did it using Last.fm.
This video : https://www.youtube.com/watch?v=jU5UyZlynaM

I wonder if Spotify has such an API? I wrote a chat bot with tmi.js and node.js.

I’m open to advice.


#2

If Spotify has an API the best place to check would be with Spotify, not here as Twitch can’t provide documentation or support for something that has nothing to do with them.


#3

I’m writing here because many bots have this feature. Maybe you are using it in your own chatbot or investigating. I searched the internet before writing here and then decided to open up a topic.


#4

You have to use the spotify API, and setup an auth to generate a token, and setup a refresh of the token. The tokens have a very short life span… an hour or something.

May also want to peek at the endpoint: https://developer.spotify.com/console/get-users-currently-playing-track


#5

I’m looking here now thank you.


#6

This does the job. https://groke.se/twitch/spotify/


#7

Thank you :slight_smile: I will try…


#8

I get the song with the request from the site. But when I add the !song command in the form of writing the error part. Do you have any suggestions about this?

Code’s

request({url: 'https://groke.se/twitch/spotify/APİ NUMBER’S, json: true}, function(err, res, json) {
if (err) {
throw err;
}
console.log(json);

client.on(‘message’, async (channel, userstate, message, self) => {

// Don't reply to messages from self or without the "!" as the first char
if (self || message[0] !== '!') {
	return;
}

// Run the !song command
	  // Output items
	  Console.log("Çalan Şarkı :  ",json);
	}, function(err) {
	  console.log('Şuan Şarkı çalmıyor..', err);
	});

#9

I have no idea where you are trying to run this, but the API works just fine. Check your chatbot documentation or the API-sites documentation on how to add it.