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 🙏

© 2024 – Pkg Stats / Ryan Hefner

frixx

v1.0.11

Published

A simple but a beginner friendly module to play music on discord. Using Spotify and YouTube.

Downloads

129

Readme

Frixx

Frixx, A simple but a beginner friendly module to play music on discord. Using Spotify and YouTube.

Prerequisites

  • discord.js - (latest)
  • @discordjs/opus
  • opusscript
  • ffmpeg-static

Installation

$ npm install frixx

Import

  • The import is for the latest EcmaScript/ES.

import { Player } from "frixx";
  • This is the default CommonJS import.

const { Player } = require("frixx");

Initialize

import {
  ApplicationCommandOptionType,
  ApplicationCommandPermissionType,
  ApplicationCommandType,
  Client,
  EmbedBuilder,
  GatewayIntentBits,
  Partials,
} from "discord.js";
import { Player } from "frixx";
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildVoiceStates,
    GatewayIntentBits.GuildMembers,
  ],
  partials: [Partials.GuildMember, Partials.Channel, Partials.GuildMember],
});
const player = new Player(client);
const TOKEN = "YOUR BOT TOKEN";
client.login(TOKEN);

new Player(client)

The player as of now only supports YouTube and Spotify as the main source to play the music. The player requires a client (Mandatory). You have to instantiate a client.

| Param | Type | Description | | ------ | ------------------- | ----------- | | client | Client | (Mandatory) |

player.toggleLoop(guild)

Toggles the loop mode.

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |


const loopCheck = player.loopEnabled;
await player.toggleLoop!(interaction.guild!);
interaction.reply({
  content: `The loop is now ${loopCheck === true ? "Enabled" : "Disabled"}`,
});

~~player.loopAdd(guild)~~

Deprecated

Turns the loop mode to on.

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

// The function is deprecated. Use the toggle loop instead.
await player.loopAdd!(interaction.guild!);
interaction.reply({
  content: "The queue is now on a loop",
});

~~player.loopRemove(guild)~~

Deprecated

Turns the loop mode to off.

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

// The function is deprecated. Use the toggle loop instead.
await player.loopRemove!(interaction.guild!);
interaction.reply({
  content: "The queue is now no longer on a loop",
});

player.pause(guild)

Pauses the current playing track

Kind: instance method of Player Throws:

  • Error

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

player?.pause!(interaction.guild!);
interaction.reply({
  content: "The music is now paused.",
});

player.seek(guild, secondsToSeek)

Seeks/Forwards the songs to xyz seconds.

Kind: instance method of Player

| Param | Description | | ------------- | -------------------------------- | | guild | The guild property - (Mandatory) | | secondsToSeek | Seconds to seek - (Mandatory) |

await player.seek!(interaction.guild!, seconds!);
interaction.followUp({
  content: `Seeked the track for ${seconds} seconds`,
});

player.resume(guild)

Resumes the paused track.

Kind: instance method of Player Throws:

  • EvalError

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

player?.resume!(interaction.guild!);
interaction.reply({
  content: "The music is now resumed.",
});

player.volume(guild, volumePercentage)

Kind: instance method of Player Throws:

  • EvalError

| Param | Description | | ---------------- | -------------------------------------- | | guild | The guild property - (Mandatory) | | volumePercentage | The volume percentage. - (Mandatory) |

const volume = interaction.options.getNumber("percentage"); // The volume needs to be a number.
await player?.volume!(interaction.guild!, volume!);

interaction.reply({
  content: `The volume is now **${volume}%**`,
});

player.clearQueue(guild)

Clears the queue. (Doesn't destroys the actual queue. Only clears all of the tracks from the track list.)

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

await player?.clearQueue!(interaction.guild!);
interaction.reply({
  content: `The queue is now cleared.`,
});

player.leaveVoiceChannel(guild)

Leaves the current voice channel that the bot is connected to.

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

const member = await interaction.guild?.members?.cache.get(interaction.user.id);
await player.leaveVoiceChannel(interaction?.guild!);
interaction.reply({
  content: `${member?.voice.channel} Left.`,
});

player.connect(guild, voiceChannelId)

Connects to the voice channel. That you're connected to..

Kind: instance method of Player

| Param | Description | | -------------- | -------------------------------------------- | | guild | The guild property - (Mandatory) | | voiceChannelId | The id of the voice channel. - (Mandatory) |

const member = await interaction.guild?.members?.cache.get(interaction.user.id);
await player.connect!(interaction.guild!, member?.voice.channelId!);
interaction.reply({
  content: `Connected to ${member?.voice?.channel}`,
});

player.addRelatedTrack(guild, member)

Adds a similar track to the current one that is playing.

Kind: instance method of Player

| Param | Description | | ------ | ---------------------------------------- | | guild | The guild property - (Mandatory) | | member | The GuildMember property - (Mandatory) |

const relatedTrack = await player.addRelatedTrack!(
  interaction.guild!,
  interaction?.user!
);
interaction.reply({
  content: `Added **${relatedTrack.youtubeTitle}** to the queue.`,
});

player.getQueue(guild)

_Get the current queue. _

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

const queue = await player.getQueue!(interaction?.guild!);
return interaction.reply({
  content: `There are total ${queue.tracks.length} tracks in the queue`,
});

player.skip(guild, type)

Skips the current playing track.

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) | | type | ChatInputCommandInteraction |

await player.skip!(interaction.guild!, interaction);

player.playPrevious(guild, type)

Plays the last/previous track again.

Kind: instance method of Player

| Param | Description | | ----- | ------------------------------------------------------ | | guild | The guild property - (Mandatory) | | type | Message or ChatInputCommandInteraction - (Mandatory) |

await interaction.deferReply();
const previousSong = await player.playPrevious!(
  interaction.guild!,
  interaction
);

player.stop(guild, leave)

Stops the current playing track & will left the voice channel (Only if you specify the "leave value to true.")

Kind: instance method of Player

| Param | Description | | ----- | ---------------------------------------------------------------------------------- | | guild | The guild property - (Mandatory) | | leave | The boolean value of whether you want the bot to leave the voice channel or not. |

await player.stop!(interaction.guild!, true);

interaction.reply({
  content: `Stop playing the track.`,
});

player.shuffle(guild)

Shuffles the current queue.

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

const shuffledQueue = player?.shuffle!(interaction.guild!);
interaction.reply({
  content: "The queue is now shuffled.",
});

player.currentTrackInformation(guild)

Shows the current track information.

Kind: instance method of Player

| Param | Description | | ----- | -------------------------------- | | guild | The guild property - (Mandatory) |

const information = await player?.currentTrackInformation!(interaction.guild!);
interaction.reply({
  content: `Name: ${information.spotifyTitle}\nDuration: ${information.spotifyDuration}\nArtists: ${information.author}`,
});

player.getPlaylist()

The function as of now currently only supports the platform YouTube & Spotify as their main source of fetching data. So aside from YouTube & Spotify no platforms will be supported.

  • Kind: instance method of Player
  • Since: Saturday, 10 December 2022
const uri = await interaction.options.getString("uri");
const m = await interaction.guild?.members.cache.get(interaction.user.id);
await interaction.deferReply();
const queue = await player.getQueue!(interaction?.guild!);
const response = await await player.getPlaylist!(
  interaction.guild!,
  `${uri}`,
  m
);
queue.tracks?.push(...response.tracks!);
interaction.followUp({
  content: `Added **${response.list?.name}** to the queue.`,
});

player.tracksAdd()

In order to add tracks to the queue, you have to specify a proper tracks array.

Kind: instance method of Player

        import { Client, ApplicationCommandOptionType } from "discord.js";
        import { Player } from "frixx";

        //Initializing the player.
        const player = new Player(client)


        client.on("interactionCreate", async(interaction) => {
          if (!interaction.isChatInputCommand()) {
          return;
        }
        if(interaction.commandName === "playlist_song_add") {
          await interaction.deferReply();
          const uri = await interaction.options.getString("playlist");
          const response = await player.getPlaylist!(interaction.guild!, uri, interaction?.member!);
          await player.tracksAdd!(interaction?.guild!, response?.tracks!);

          interaction.followUp({
          content: `Added ${response?.list.name} to the current queue.`
          })
        }

        })

        client.on("ready", () => {

            await client.guilds.cache.get("Your guild id here.")?.commands.set(
              [{
              name: "playlist_song_add",
              description: "Adds some songs to the queue.",
              options: [{
              name: "playlist",
              description : "Specify the playlist uri.",
              type: ApplicationCommandOptionType.String,
              required: true
            }]
            )
          }
        ])

        return console.log("The client is now up and ready to go.")
        })

        client.login("Your Bot Token.")

player.play()

The player as of now only supports YouTube and Spotify as the main playing source.

  • Kind: global function

  • Since: Sunday, 11 December 2022

  • Author: TrishCX

| Param | Description | | -------------- | ------------------------------------------------------------------------- | | guild | The "Guild" property from the discord.js. | | query | The query to play. This can be whether a uri/url or a simple search term. | | voiceChannelId | The voice channel id. | | type | The type, it can be whether a Message or ChatInputCommandInteraction. | | member | The GuildMember field from the discord.js itself. |

Example

  • TypeScript
        const query = interaction.options.getString("query");
          await interaction.deferReply();
          const member = await interaction.guild?.members.cache.get(
            interaction.user.id
          )!.voice;
          const m = await interaction.guild?.members.cache.get(interaction.user.id);
          const guild = interaction?.guild!;
            interaction.guild!,
            `${query}`,
            `${member?.channel?.id}`,
            m!,
            interaction,
          );
  • JavaScript
const query = interaction.options.getString("query");
await interaction.deferReply();
const member = await interaction.guild?.members.cache.get(interaction.user.id)
  .voice;
const m = await interaction.guild?.members.cache.get(interaction.user.id);
const guild = interaction?.guild;
await player?.play(
  interaction.guild,
  `${query}`,
  `${member?.channel?.id}`,
  interaction,
  m
);