Skip to content

A Discord music bot that can track what someone's playing on Spotify and play it live in a voice channel for everyone to listen along

License

Notifications You must be signed in to change notification settings

rofe-dl/tamashi

Repository files navigation

T a m a s h i

tamashi_img

A discord bot that can follow what a Spotify user is listening to and play it in a voice channel so everyone can listen in simultaneously. Although this feature already exists in Discord with the Spotify integration (Listen Along), only premium Spotify users get to use it. This bot can be a viable alternative.

Apart from that, it also supports manually playing songs with the /play command.

And no, I don't have plans to host and make this a public bot for everyone. This is just a hobby project for private use in my Discord servers. Please set it up yourselves.

Key Commands

Command Description
/followme Makes the bot track what you're currently playing on Spotify!
/unfollowme Makes the bot stop tracking the current user's Spotify.
/followwho Tells you who the bot is following.
/play Play a song using a search phrase or URLs from Spotify or YouTube.
/pause Pauses the currently playing song.
/resume Resumes the currently playing song if it's paused.
/stop Stops the currently playing song.
/currently-playing Shows the song that's currently playing

Setup Instructions

Requirements

  • Node.js v19 or above.
  • Docker Compose.

Steps

To tinker with it locally

  1. Clone the repo and run npm i in this directory.
  2. Make Spotify app in your Spotify developer dashboard.
  3. Make a Discord app in your Discord developer portal.
  4. Make a free MongoDB database using Atlas.
  5. Make a file called application.yml and copy the contents from sample.lavalink.application.yml into it. Fill up the fields marked #INPUT with your own values.
  6. Make a file called config.json in ./src folder and fill it with your info just like in sample.config.json.
  7. Run docker compose up in the project directory. (In the future, do docker compose down to delete the containers if you wanna start clean, or docker compose stop to just stop the containers)
  8. To deploy the commands to your Discord servers, run npm run deploycommands.
  9. Run npm run start.

To use the whole thing as a Docker image

  1. Make Spotify app in your Spotify developer dashboard.
  2. Make a Discord app in your Discord developer portal.
  3. Make a free MongoDB database using Atlas.
  4. Download the docker-compose.prod.yml file.
  5. In the same directory, make a file called application.yml and copy the contents from sample.lavalink.application.yml into it. Fill up the fields marked #INPUT with your own values.
  6. In the same directory, make a file called config.json in ./src folder and fill it with your info just like in sample.config.json
  7. Run docker compose -f docker-compose.prod.yml up in the directory. (In the future, do docker compose -f docker-compose.prod.yml down to delete the containers if you wanna rebuild them, or docker compose -f docker-compose.prod.yml stop to just stop the containers)
  8. To make the slash commands work, enter the shell of the container by running docker exec -ti <container name of tamashi-bot> /bin/bash. Then, run npm run deploycommands. Exit the shell using exit command. You'll only have to run this once. However, if you make any changes to the command names or add/delete new ones, deploy the commands again.

Things to look out for

  1. In the Discord developer portal, when generating the invite link for the bot, set the scopes to bot, voice and application.commands. Then give it admin access from the bot permissions.
  2. To test the bot locally, you can setup ngrok to test the callback URL from Spotify for a public URL. You will also have to set this in the Spotify application settings from the dashboard (in the dashboard make sure it ends with /tamashi/callback). The public URL ngrok gives you will also have to be put in config.json file.
  3. Without a quota extension from Spotify, you can have a maximum of 25 users (excluding yourself) use the /followme command. You'll have to add their emails in the Users And Access section of the dashboard.

Tech Stack

  • NodeJS
  • Discord.js
  • Express
  • MongoDB with Mongoose
  • Redis
  • Lavalink
  • Docker

To release new versions, change tag in docker-compose.prod.yml and package.json. Build the new images using docker compose -f docker-compose.prod.yml build --no-cache. Push it using docker compose -f docker-compose.prod.yml push.