0.0.21 • Published 5 months ago

aoi.js-lavalink v0.0.21

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

aoi.js-lavalink

aoi.js-lavalink is a package used to bring the functionality of lavalink to aoi.js fast and easy.

Installation

Get started by installing the latest version of aoi.js-lavalink within your project.

npm install aoi.js-lavalink@latest

Or if you're feeling lucky, install the development version with new features.

npm install github:aoi.js-lavalink

Setup

To add the functionality to your client, we have to import the lavalinkManager class.

const { AoiClient, LoadCommands } = require("aoi.js");
const { lavalinkManager } = require("aoi.js-lavalink");

const client = new AoiClient({
  token: "DISCORD BOT TOKEN",
  prefix: "DISCORD BOT PREFIX",
  intents: ["MessageContent", "Guilds", "GuildMessages", "GuildVoiceStates"],
  events: ["onInteractionCreate", "onMessage"],
  database: {
    type: "aoi.db",
    db: require("@akarui/aoi.db"),
    dbType: "KeyValue",
    tables: ["main"],
    securityKey: "a-32-characters-long-string-here",
  },
});

const lavalink = new lavalinkManager(client, {
  host: "0.0.0.0", // Server Address
  port: 0000, // Server Port
  password: "youshallnotpass", // Lavalink Server Password
  secure: false, // HTTP/HTTPS protocol
  events: ["trackStart", "trackEnd"], // Array of events that can be used.
  // debug: true // Used to enable debugging, not pretty but could help to debug your issues.
});

// Adding events
lavalink.addEvent("trackStart", {
  code: `$log[Now playing $trackInfo[uri]!]`
});

You can also use events in your command handler!

const loader = new LoadCommands(client);
loader.load(client.cmd, "./commands");

Then in your file:

/commands/trackStart.js

module.exports = {
  name: "some name", // optional!
  type: `trackStart`,
  channel: "some channel id", // optional!
  code: `Some code`
}

Aoi.js will display a "failed to load" error if you enable logging, but you can disregard that :)

Make sure you add the events to the events: [] in your lavalink setup to make them work.

You can also enable debug mode, to debug your issues. (will display when events are triggered, what events are registered)

debug: true

for that in your lavalink setup


Functions

Absolutely! Here's the comprehensive list of all the functions in a modern README.md style:

Music Player Functions

$joinVoice

Connects the bot to a specified voice channel.

$joinVoice[voiceId;returnChannel?]
  • voiceId (required)
  • returnChannel (optional, default: "false")

Example:

$joinVoice[123456789012345678;true]

$playTrack

Plays a track based on the query in the specified source.

$playTrack[query;source?;guildId?]
  • query (required)
  • source^2 (optional, default: "youtube")
  • guildId (optional, default: current guild ID)

Example:

$playTrack[Despacito;youtube;123456789012345678]

$trackInfo

Retrieves information about a track in the player's queue at a specific index.

$trackInfo[index;property]
  • index (required)
  • property (required)

Example:

$trackInfo[1;title]

$loop

Sets the loop type for the player (track, queue, none).

$loop[type]
  • type (required)

Example:

$loop[track]

$loopStatus

Retrieves the current loop status of the player.

$skipTrack

Skips the currently playing track in the queue.

$skipTo

Skips to a specific track in the queue based on its index.

$skipTo[index]
  • index (required)

$seekTo

Seeks to a specific position (in milliseconds) in the currently playing track.

$seekTo[ms]
  • ms (required)

$removeTrack

Removes a track from the queue at the specified position.

$removeTrack[position]
  • position (required)

$getFilters

Retrieves filters applied to the player.

$getFilters[type]
  • type (required)

$toggleFilters

Toggles specified audio filters and returns applied filters if requested.

$toggleFilters[filterType;returnFilters]
  • filterType (required)
  • returnFilters (optional, default: "false")

$setVolume

Sets the volume of the player.

$setVolume[volume]
  • volume (required)

$shuffleQueue

Shuffles the queue of tracks.

$unShuffleQueue

Restores the original order of the queue after shuffling.

$autoPlay

Enables or disables autoplay feature for the player.

$autoPlay[source]
  • source^2 (optional, default: "youtube")

$searchTrackquery;index?;format?

Searches for tracks based on the provided query and index.

  • query (required)
  • index? (optional, default: "0")
  • format? (optional, default: false)

$pauseTrack

Pauses the currently playing track.

$resumeTrack

Resumes the paused track.

$playerStatus

Retrieves the status of the player.

Events^3

Event NamesParametersDescription
nodeCreatenodeEmitted once a node gets created
nodeConnect (default^1)nodeEmits when a node connects
nodeReconnect (default^1)nodeEmits when a node attempts a reconnect
nodeDisconnect (default^1)node, reason: { code?: number, reason?: string }Emits when a node disconnects
nodeErrornode, errorEmits when a node throws errors
nodeRawpayloadEmits every payload from a Node
playerCreateplayerEmits when a player gets created
playerDestroyplayerEmits when a player gets destroyed
queueEndplayer, track, payloadEmits when the queue End
playerMoveplayer, initChannel, newChannelEmits when the player moves from a Voice Channel to another one
playerDisconnectplayer, oldChannelEmits when the player Leaves the VC
trackStartplayer, track, payloadEmits when a track starts to play
trackEndplayer, track, payloadEmits when a track ends playing
trackStuckplayer, track, payloadEmits when a track gets stucked and skips the track
trackErrorplayer, track, payloadEmits when a track errors and skips it
socketClosedplayer, payloadEmits when a connection gets closed

^1: Executed by default, no matter what. Cannot be disabled as of now, maybe in the future as another feature.

^2: Additional Sources besides YouTube and Soundcloud require additional setup on your side. Including the editing of your application.yml and more.

^3: Events are used to emit Player Events, example usage of using events:

  ```js
    <lavalinkInstance>.on(<event>, {
        code: `
            Your aoi.js code
        `
    });
    ```

  Channel, author and guild are automatically passed, meaning you can use guild, channel and author related functions without any issues.
0.0.21

5 months ago

0.0.2

5 months ago

0.0.12-a

5 months ago

0.0.11

5 months ago

0.0.12

5 months ago

0.0.1

5 months ago

0.0.1-beta

5 months ago