0.1.3-beta • Published 5 months ago
@terron/djs-music v0.1.3-beta
Classes
Player
The Player
class is the main component responsible for managing music playback in your bot.
Constructor (Options)
defaultVolume
- Option controlling the default volume of the player. (Default:
100
)
leaveAfterEnd
- Option determining whether to leave the voice channel after the player queue ends. (Default:
true
)
keepVoiceIfExists
- Option controlling whether to maintain the voice connection if already exists. (Default:
true
)
client
- Discord.js client instance.
Methods
constructor(options)
- Initializes a new instance of the Player class with optional configuration options.
async search(query, trackLimit = 10)
- Searches YouTube for videos based on the provided query.
query
: The search query.trackLimit
: Maximum number of tracks to retrieve (Default:10
).
async play(channelResolvable, query, voiceJoinOptions = {})
- Starts playing a track in the specified voice channel.
channelResolvable
: Resolvable representing the voice channel to join.query
: The search query or URL of the track to play.voiceJoinOptions
: Options for joining the voice channel (Default:{}
).
pause(guildResolvable)
- Pauses playback in the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild where playback should be paused.
unpause(guildResolvable)
- Resumes playback in the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild where playback should be resumed.
setVolume(guildResolvable, volume)
- Sets the volume of playback in the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild where volume should be set.volume
: Volume level to set.
skip(guildResolvable)
- Skips the current track and starts playing the next in queue for the specified guild.
guildResolvable
: Resolvable representing the guild where the track should be skipped.
stop(guildResolvable)
- Stops playback and optionally leaves the voice channel in the specified guild.
guildResolvable
: Resolvable representing the guild where playback should be stopped.
async connect(channelResolvable, voiceJoinOptions = {})
- Joins the specified voice channel.
channelResolvable
: Resolvable representing the voice channel to join.voiceJoinOptions
: Options for joining the voice channel (Default:{}
).
paused(guildResolvable)
- Checks if playback is paused in the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild to check.
getQueue(guildResolvable)
- Retrieves the current playback queue for the specified guild.
guildResolvable
: Resolvable representing the guild to fetch the queue.
shuffleQueue(guildResolvable)
- Shuffles the current playback queue for the specified guild.
guildResolvable
: Resolvable representing the guild where the queue should be shuffled.
nowPlaying(guildResolvable)
- Retrieves information about the currently playing track in the specified guild.
guildResolvable
: Resolvable representing the guild to fetch the currently playing track.
addFilter(guildResolvable, ffmpegFilter)
- Adds an FFmpeg audio filter for the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild where the filter should be added.ffmpegFilter
: FFmpeg filter to add.
setFilter(guildResolvable, ffmpegFilter)
- Sets an FFmpeg audio filter, replacing existing filters for the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild where the filter should be set.ffmpegFilter
: FFmpeg filter to set.
removeFilter(guildResolvable, ffmpegFilter)
- Removes a specific FFmpeg audio filter from the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild where the filter should be removed.ffmpegFilter
: FFmpeg filter to remove.
resetFilters(guildResolvable)
- Resets all audio filters for the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild where filters should be reset.
restartCurrentTrack(guildResolvable)
- Restarts the current track in the specified guild's voice channel.
guildResolvable
: Resolvable representing the guild where the track should be restarted.
Filters
The Filters
class provides static methods for creating FFmpeg audio filters.
Methods
nightcore(strength = 1.25)
- Creates a "nightcore" audio filter with the specified strength.
strength
: The strength of the nightcore effect (default:1.25
).
bassboost(strength = 10)
- Creates a "bassboost" audio filter with the specified strength.
strength
: The strength of the bassboost effect (default:10
).
reverb(strength = 50)
- Creates a "reverb" audio filter with the specified strength.
strength
: The strength of the reverb effect (default:50
).
speed(strength = 1)
- Creates a "speed" audio filter with the specified strength.
strength
: The strength of the speed effect (default:1
).
PlayerEvents
The PlayerEvents
class defines constant values for events related to the player functionality.
Constants
VoiceJoin
- Indicates the event when the bot joins a voice channel.
- Value:
'voiceJoin'
- Value:
VoiceLeft
- Indicates the event when the bot leaves a voice channel.
- Value:
'voiceLeft'
- Value:
VoiceUpdate
- Indicates the event when there is an update in the bot's voice channel connection.
- Value:
'voiceUpdate'
- Value:
TrackAdd
- Indicates the event when a track is added to the player's queue.
- Value:
'trackAdd'
- Value:
TrackStart
- Indicates the event when a track starts playing.
- Value:
'trackStart'
- Value:
QueueEnd
- Indicates the event when the player's queue ends.
- Value:
'queueEnd'
- Value:
UpdateLoopStatus
- Event triggered when the loop status for the queue or track is updated.
- Value:
'updateLoopStatus'
- Value:
Example
const { Client, GatewayIntentBits } = require('discord.js');
const { Player, PlayerEvents, Filters } = require('@terron/djs-music');
const client = new Client({
intents: ['Guilds', 'GuildMessages', 'MessageContent', 'GuildVoiceStates']
.map(x => GatewayIntentBits[x])
});
client.player = new Player({
client,
defaultVolume: 75,
leaveAfterEnd: false
});
client.on('ready', () => console.log('Client is ready!'));
// commands
client.on('messageCreate', async msg => {
if (!msg.content || !msg.guild) return;
const args = msg.content.split(' ');
const cmd = args.shift();
if (cmd == '!play') {
client.player.setFilter(msg.guild, Filters.nightcore());
client.player.play(msg.member.voice?.channel, args.join(' '));
}
if (cmd == '!stop') {
client.player.stop(msg.guildId);
}
});
// player events
client.player.on(PlayerEvents.VoiceJoin, channel => console.log(`Client join in ${channel.name}!`));
client.player.on(PlayerEvents.VoiceLeft, channel => console.log(`Client left from ${channel.name}!`));
client.player.on(PlayerEvents.TrackStart, track => {
console.log(`Started track ${track.title} by ${track.author.name}!`)
});
0.1.3-beta
5 months ago
0.1.0-beta
5 months ago
0.1.1-beta
5 months ago
0.1.2-beta
5 months ago
0.0.7-beta
1 year ago
0.0.6-beta
1 year ago
0.0.5-beta
1 year ago
0.0.4-beta
1 year ago
0.0.3-beta
1 year ago
0.0.2-beta
1 year ago
0.0.1-beta
1 year ago