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
-
↳
Spotify
Table of contents
Constructors
Properties
Methods
- buildResponse
- buildUnresolved
- check
- decodeSpotifyShortLink
- fetch
- fetchAlbum
- fetchArtist
- fetchPlaylist
- fetchPlaylistTracks
- fetchTrack
- load
- requestToken
- resolve
Constructors
constructor
• new Spotify(options
): Spotify
Parameters
Name | Type |
---|---|
options | Omit <SpotifyOptions , "token" | "authorization" | "interval" > |
Returns
Overrides
Defined in
plugins/spotify/Spotify.ts:256
Properties
_resolve
• Private
_resolve: (__namedParameters
: ResolveOptions
) => any
Type declaration
▸ («destructured»
): any
Parameters
Name | Type |
---|---|
«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
Defined in
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
Name | Type | Description |
---|---|---|
loadType | loadType | The type of data being loaded. |
tracks | any | The tracks data. |
playlistName? | string | The name of the playlist (optional). |
exceptionMsg? | string | The 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
Name | Type | Description |
---|---|---|
track | SpotifyTrack | The Spotify track object. |
requester | any | The 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
Name | Type | Description |
---|---|---|
url | string | The URL to check. |
Returns
boolean
- True if the URL is a Spotify URL, false otherwise.
Defined in
plugins/spotify/Spotify.ts:286
decodeSpotifyShortLink
▸ decodeSpotifyShortLink(options
): Promise
<any
>
Decodes a Spotify short link and resolves the resulting Spotify URL.
Parameters
Name | Type | Description |
---|---|---|
options | ResolveOptions | The 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
Name | Type | Description |
---|---|---|
query | string | The search query. |
source | string | The source of the request. |
requester | any | The 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
Name | Type | Description |
---|---|---|
id | string | The ID of the album. |
requester | any | The 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
Name | Type | Description |
---|---|---|
id | string | The ID of the artist. |
requester | any | The 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
Name | Type | Description |
---|---|---|
id | string | The ID of the playlist. |
requester | any | The 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
Name | Type | Description |
---|---|---|
spotifyPlaylist | SpotifyPlaylist | The 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
Name | Type | Description |
---|---|---|
id | string | The ID of the track. |
requester | any | The 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
Name | Type | Description |
---|---|---|
ruvyrias | Ruvyrias | The Ruvyrias instance. |
Returns
Promise
<void
>
Overrides
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
Name | Type | Description |
---|---|---|
options | ResolveOptions | The resolve options including query, source, and requester. |
Returns
Promise
<any
>
- The resolved data from the Spotify API.