npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

spotify-discord-player

v1.0.0-beta.2

Published

A Spotify music player for Discord bots with full track and playlist support

Readme

Spotify Discord Player

A powerful and easy-to-use Spotify music player for Discord bots with full track and playlist support.

Installation

npm install spotify-discord-player

Note: This package uses opusscript for audio encoding. If you prefer better performance, you can optionally install @discordjs/opus instead.

Features

  • 🎵 Play Spotify tracks and playlists
  • 📋 Queue management with shuffle and loop support
  • 🎚️ Basic player controls (play, pause, resume, stop)
  • 🔄 Event-based architecture
  • 📱 TypeScript support

Prerequisites

  • Node.js 16.9.0 or newer
  • Discord.js v14
  • A Spotify Developer account and application
  • A Discord bot token

Setup

  1. Create a Spotify application at Spotify Developer Dashboard
  2. Get your Spotify Client ID and Client Secret
  3. Create a Discord bot at Discord Developer Portal
  4. Enable the voice permissions for your bot

Usage

Here's a basic example of how to use the player:

const { Client, GatewayIntentBits } = require('discord.js');
const { 
    PlayerManager ,
    SpotifyAPI,
    Track
} = require('spotify-discord-player');
const { joinVoiceChannel } = require('@discordjs/voice');

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent
    ]
})
const playerManager = new PlayerManager();
const spotify = new SpotifyAPI('YOUR_SPOTIFY_CLIENT_ID', 'YOUR_SPOTIFY_CLIENT_SECRET');

client.once('ready', () => {
    console.log('Bot is ready!');
    spotify.initialize();
});

client.on('messageCreate, async (message) => {
    if (message.author.bot) return;
    if (message.content.startsWith('!play')) {
        // Get the Spotify track or playlist URL from the message
        const url = message.content.split(' ')[1];
        // Join the voice channel
        const voiceChannel = message.member.voice.channel;
        if (!voiceChannel) {
            return message.reply('You must be in a voice channel to use this command.');
        }
        const connection = joinVoiceChannel({
            channelId: voiceChannel.id,
            guildId: message.guild.id,
            adapterCreator: message.guild.voiceAdapterCreator
        })
        // Get or create a player for the voice channel
        let player = playerManager.get(message.guildId);
        if (!player) {
            player = playerManager(message.guildId, connection);
        }
        try {
            // Extract Sptofiy ID from URL
            const trackId = url.split('/')[4];
            const trackData = await spotify.getTrack(trackId);
            const track = new Track(trackData);
            // Add the track to the player queue and play it
            player.getQueue().add(track);
            if (!player.getQueue().nowPlaying) {
                await player.play(track);
                message.reply(`Now playing: ${track.title}`);
            } else {
                message.reply(`Added to queue: ${track.title}`);
            }
        } catch (error) {
            console.error('Error playing track:', error);
            message.reply('An error occurred while playing the track. Please try again.');
        }
    }
})

client.login(process.env.DISCORD_TOKEN);

Events

The player emits several events you can listen to:

player.on('trackStart', (track) => {
    console.log(`Now playing: ${track.title}`);
});

player.on('trackEnd', (track) => {
    console.log(`${track.title} has ended.`);
});

player.on('queueEnd', () => {
    console.log('Queue has ended.');
});

player.on('error', (error) => {
    console.error('An error occurred:', error);
});

API Reference

PlayerManager

  • create(guildId: string, connection: VoiceConnection): Player
  • get(guildId: string): Player | undefined
  • delete(guildId: string): boolean

Player

  • play(track: Track): Promise<void>
  • pause(): boolean
  • resume(): boolean
  • stop(): boolean
  • getQueue(): Queue

Queue

  • add(track: Track | Track[]): void
  • remove(index: number): Track | undefined
  • clear(): void
  • shuffle(): void
  • next(): Track | null
  • size: number
  • nowPlaying: Track | null

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.