Like @Steven Oh mentioned in his latest post Perfect Pitch Game In Swift UI , I was also assigned to create a music-related game for my music class. Since I was getting used to the Python discord library at the time, I decided to create a musical Discord bot using Spotify.
Discord is a communication platform which lets developers create their own bots - automated users that can perform certain actions like playing songs in voice channels, kicking people out of channels, and more.
I had this idea to test people's knowledge of music by combining Discord with Spotify. They can test their understanding of their own playlists - for example, do you know the name of all the songs in your playlist when you hear the music? - or test their understanding of today's trending playlists.
Make sure to join a voice channel when playing this game. It's a music game after all!
!featured
to play a random playlist from Spotify's featured playlists. Essentially, it means that songs from any playlists created by Spotify may be different for different users.We recently changed the way some of our Spotify-curated playlists work, so that now they will be personalized according to individual users' tastes and listening habits. In practice, this means that the same Spotify playlist can contain different songs depending on the user who is viewing the playlist.
!nextplaylist
or !n
for short !playlist spotify_uri
to play a specific playlist !playlist spotify:playlist:37i9dQZF1DX30qK0lxZtlE
will play a specific playlist !nextplaylist
command will not be used for this game mode.Once you choose what playlist you want to play, the bot will randomly choose a song from that playlist and a question from one of the 3 choices below.
What is the album name of X?
Who is the artist of song X?
What is the name of the song currently playing?
(in the voice channel) Featured playlist
Specific playlist
The full code can be found on GitHub here
An overview of libraries used:
spotipy
library to interact with Spotify BeautifulSoup
and re
(regex) to scrape the YouTube link from the youtube search results youtube-dl
to download the song to my local folder once I obtained the link The biggest challenge was determining which classes I need to create and what roles each one should be responsible for. In the end I settled with User
, Playlist
and Song
classes with no hierarchies, but I am still not sure if this was the right choice.
This is my third project with the Python Discord library, but I am still not 100% comfortable with asynchronous programming using Python's await
and async
keywords. In addition, I often have doubts as to the structure of my code, as I often find myself using global
variables, something which is not considered best practice in Python. I read somewhere that this can be resolved by using Cogs , so I will give this a try on my next discord bot.