- discord.js - (latest)
- @discordjs/opus
- opusscript
- ffmpeg-static
$ npm install frixx
import { Player } from "frixx";
const { Player } = require("frixx");
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);
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) |
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"}`,
});
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",
});
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",
});
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.",
});
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`,
});
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.",
});
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}%**`,
});
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.`,
});
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.`,
});
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}`,
});
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.`,
});
_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`,
});
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);
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
);
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.`,
});
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.",
});
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}`,
});
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.`,
});
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.")
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
);