Made setToken async

This commit is contained in:
killer069 2022-01-04 15:20:38 +05:30
parent ddcb71c018
commit d68fb60756
2 changed files with 13 additions and 4 deletions

View File

@ -237,10 +237,10 @@ export async function refreshToken(): Promise<boolean> {
return true;
}
export function setSpotifyToken(options: SpotifyDataOptions) {
export async function setSpotifyToken(options: SpotifyDataOptions) {
spotifyData = options;
spotifyData.file = false;
refreshToken();
await refreshToken();
}
export { SpotifyTrack, SpotifyAlbum, SpotifyPlaylist };

View File

@ -39,14 +39,23 @@ interface tokenOptions {
* }
* }) // YouTube Cookies
*
* await play.setToken({
* spotify : {
* client_id: 'ID',
client_secret: 'secret',
refresh_token: 'token',
market: 'US'
* }
* }) // Await this only when setting data for spotify
*
* play.setToken({
* useragent: ['Your User-agent']
* }) // Use this to avoid 429 errors.
* ```
* @param options {@link tokenOptions}
*/
export function setToken(options: tokenOptions) {
if (options.spotify) setSpotifyToken(options.spotify);
export async function setToken(options: tokenOptions) {
if (options.spotify) await setSpotifyToken(options.spotify);
if (options.soundcloud) setSoundCloudToken(options.soundcloud);
if (options.youtube) setCookieToken(options.youtube);
if (options.useragent) setUserAgent(options.useragent);