Skip to main content

ruvyrias / Exports / Spotify

Installation

// Just import the class from Ruvyrias
const { Spotify } = require('ruvyrias');

Example usage basic bot

const { Client, GatewayIntentBits } = require('discord.js');
const { Spotify } = require('ruvyrias');

const spotify = new Spotify({
clientID: 'client-id-here',
clientSecret: 'client-secret-here',
});

const RuvyriasOptions = {
library: 'discord.js',
defaultPlatform: 'spsearch',
plugins: [spotify],
};

const nodes = [
{
name: 'local-node',
host: 'localhost',
port: 2333,
password: 'youshallnotpass',
},
];

// The entire code of a bot can be found at the main page, i'll not repeat all things here
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent,
],
});

client.ruvyrias = new Ruvyrias(client, nodes, RuvyriasOptions);

/**
* You can use the source property to search by name or it will use the defaultPlatform to search by name
* Links will work directly, and it serves to any platform, but plugins has to be loaded before (unless you have lavaSrc)
*/
const res = await client.ruvyrias.resolve({ query: 'alan walker alone', source: 'spsearch', requester: message.author });

Class: Spotify

Represents the Spotify class, extending the base Plugin class.

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Spotify(options): Spotify

Parameters

NameType
optionsOmit<SpotifyOptions, "token" | "authorization" | "interval">

Returns

Spotify

Overrides

Plugin.constructor

Defined in

plugins/spotify/Spotify.ts:256

Properties

_resolve

Private _resolve: (__namedParameters: ResolveOptions) => any

Type declaration

▸ («destructured»): any

Parameters
NameType
«destructured»ResolveOptions
Returns

any

Defined in

plugins/spotify/Spotify.ts:253


baseURL

Private baseURL: string = 'https://api.spotify.com/v1'

Defined in

plugins/spotify/Spotify.ts:250


name

Readonly name: string

The name of the plugin.

Inherited from

Plugin.name

Defined in

src/Plugin.ts:8


options

options: SpotifyOptions

Defined in

plugins/spotify/Spotify.ts:252


ruvyrias

ruvyrias: Ruvyrias

Defined in

plugins/spotify/Spotify.ts:251


spotifyManager

spotifyManager: SpotifyManager

Defined in

plugins/spotify/Spotify.ts:254

Methods

buildResponse

buildResponse(loadType, tracks, playlistName?, exceptionMsg?): any

Builds a response object based on the provided loadType, tracks, playlistName, and exception message.

Parameters

NameTypeDescription
loadTypeloadTypeThe type of data being loaded.
tracksanyThe tracks data.
playlistName?stringThe name of the playlist (optional).
exceptionMsg?stringThe exception message (optional).

Returns

any

  • The built response object.

Defined in

plugins/spotify/Spotify.ts:584


buildUnresolved

buildUnresolved(track, requester): Promise<Track>

Builds an unresolved Track object based on the provided Spotify track and requester information.

Parameters

NameTypeDescription
trackSpotifyTrackThe Spotify track object.
requesteranyThe requester information.

Returns

Promise<Track>

  • The unresolved Track object.

Defined in

plugins/spotify/Spotify.ts:551


check

check(url): boolean

Checks if the provided URL is a Spotify URL.

Parameters

NameTypeDescription
urlstringThe URL to check.

Returns

boolean

  • True if the URL is a Spotify URL, false otherwise.

Defined in

plugins/spotify/Spotify.ts:286


decodeSpotifyShortLink(options): Promise<any>

Decodes a Spotify short link and resolves the resulting Spotify URL.

Parameters

NameTypeDescription
optionsResolveOptionsThe resolve options including query, source, and requester.

Returns

Promise<any>

  • The resolved data from the Spotify API.

Defined in

plugins/spotify/Spotify.ts:361


fetch

fetch(query, source, requester): Promise<any>

Fetches data from Spotify based on the provided query, source, and requester information.

Parameters

NameTypeDescription
querystringThe search query.
sourcestringThe source of the request.
requesteranyThe requester information.

Returns

Promise<any>

  • The resolved data from the Spotify API.

Defined in

plugins/spotify/Spotify.ts:503


fetchAlbum

fetchAlbum(id, requester): Promise<any>

Fetches an album from Spotify and resolves its tracks.

Parameters

NameTypeDescription
idstringThe ID of the album.
requesteranyThe requester information.

Returns

Promise<any>

  • The resolved data from the Spotify API.

Defined in

plugins/spotify/Spotify.ts:411


fetchArtist

fetchArtist(id, requester): Promise<any>

Fetches an artist from Spotify and resolves their top tracks.

Parameters

NameTypeDescription
idstringThe ID of the artist.
requesteranyThe requester information.

Returns

Promise<any>

  • The resolved data from the Spotify API.

Defined in

plugins/spotify/Spotify.ts:445


fetchPlaylist

fetchPlaylist(id, requester): Promise<any>

Fetches a playlist from Spotify and resolves its tracks.

Parameters

NameTypeDescription
idstringThe ID of the playlist.
requesteranyThe requester information.

Returns

Promise<any>

  • The resolved data from the Spotify API.

Defined in

plugins/spotify/Spotify.ts:377


fetchPlaylistTracks

fetchPlaylistTracks(spotifyPlaylist): Promise<void>

Fetches additional tracks for a Spotify playlist.

Parameters

NameTypeDescription
spotifyPlaylistSpotifyPlaylistThe Spotify playlist object.

Returns

Promise<void>

  • A Promise that resolves when the tracks are fetched.

Defined in

plugins/spotify/Spotify.ts:531


fetchTrack

fetchTrack(id, requester): Promise<any>

Fetches a track from Spotify and resolves it.

Parameters

NameTypeDescription
idstringThe ID of the track.
requesteranyThe requester information.

Returns

Promise<any>

  • The resolved data from the Spotify API.

Defined in

plugins/spotify/Spotify.ts:480


load

load(ruvyrias): Promise<void>

Loads the Spotify plugin into the Ruvyrias instance.

Parameters

NameTypeDescription
ruvyriasRuvyriasThe Ruvyrias instance.

Returns

Promise<void>

Overrides

Plugin.load

Defined in

plugins/spotify/Spotify.ts:275


requestToken

requestToken(): Promise<void>

Requests an access token from the Spotify API using client credentials.

Returns

Promise<void>

  • A promise that resolves when the token is successfully requested and set.

Defined in

plugins/spotify/Spotify.ts:294


resolve

resolve(options): Promise<any>

Resolves a Spotify query, handling various types such as playlists, tracks, albums, and artists. If a token is not available, it requests one using client credentials.

Parameters

NameTypeDescription
optionsResolveOptionsThe resolve options including query, source, and requester.

Returns

Promise<any>

  • The resolved data from the Spotify API.

Defined in

plugins/spotify/Spotify.ts:324