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

trixxy-youtube

v1.0.0

Published

A package for playing YouTube audio in Discord bots.

Readme

trixxy-youtube

Installation

npm install trixxy-youtube

Dependencies

This package relies on the following npm packages:

  • discord.js
  • @discordjs/voice
  • ytdl-core
  • ytsr

Make sure these are installed in your project.

Usage

Here's how to use the TrixxyYouTube class in your Discord bot:

const { Client, GatewayIntentBits } = require('discord.js');
const TrixxyYouTube = require('trixxy-youtube');

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildVoiceStates,
  ],
});

const youtubePlayer = new TrixxyYouTube();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('interactionCreate', async interaction => {
  if (!interaction.isCommand()) return;

  const { commandName } = interaction;

  if (commandName === 'play') {
    await interaction.deferReply();
    const query = interaction.options.getString('query');
    try {
      await youtubePlayer.addAndPlay(query, interaction);
    } catch (error) {
      console.error(error);
      await interaction.followUp(`There was an error trying to play music: ${error.message}`);
    }
  } else if (commandName === 'skip') {
    await interaction.deferReply();
    try {
      await youtubePlayer.skip(interaction);
    } catch (error) {
      console.error(error);
      await interaction.followUp(`There was an error trying to skip music: ${error.message}`);
    }
  } else if (commandName === 'stop') {
    await interaction.deferReply();
    try {
      await youtubePlayer.stop(interaction);
    } catch (error) {
      console.error(error);
      await interaction.followUp(`There was an error trying to stop music: ${error.message}`);
    }
  }
});

client.login('YOUR_BOT_TOKEN');

// Example of how to register slash commands (run once)
// This is a simplified example, you should register your commands properly
/*
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');

const commands = [
  {
    name: 'play',
    description: 'Plays a song from YouTube.',
    options: [
      {
        name: 'query',
        type: 3, // STRING
        description: 'The YouTube URL or search query.',
        required: true,
      },
    ],
  },
  {
    name: 'skip',
    description: 'Skips the current song.',
  },
  {
    name: 'stop',
    description: 'Stops the music and clears the queue.',
  },
];

const rest = new REST({ version: '9' }).setToken('YOUR_BOT_TOKEN');

(async () => {
  try {
    console.log('Started refreshing application (/) commands.');

    await rest.put(
      Routes.applicationGuildCommands('YOUR_CLIENT_ID', 'YOUR_GUILD_ID'),
      { body: commands },
    );

    console.log('Successfully reloaded application (/) commands.');
  } catch (error) {
    console.error(error);
  }
})();
*/

TrixxyYouTube Class Methods

constructor()

Initializes the YouTube player, queue, and voice connection. Sets up event listeners for idle and error states of the audio player.

join(member)

Joins the voice channel of the provided GuildMember.

  • member: The GuildMember object whose voice channel to join.

Throws: Error if the member is not in a voice channel.

play(url, interaction)

Plays a YouTube audio stream from the given URL. Automatically joins the voice channel if not already connected.

  • url: The YouTube video URL to play.
  • interaction: The Discord Interaction object to send follow-up messages.

addAndPlay(query, interaction)

Adds a song to the queue. If the query is not a valid YouTube URL, it will search YouTube for the query and add the first result. If nothing is currently playing, it will start playback immediately.

  • query: A YouTube URL or a search query (e.g., "Never Gonna Give You Up").
  • interaction: The Discord Interaction object to send follow-up messages.

skip(interaction)

Skips the current song and plays the next one in the queue. If only one song is in the queue, it will stop playback.

  • interaction: The Discord Interaction object to send follow-up messages.

stop(interaction)

Stops the current playback, clears the entire queue, and disconnects from the voice channel.

  • interaction: The Discord Interaction object to send follow-up messages.