Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
add autorefresh to spotify token
Browse files Browse the repository at this point in the history
  • Loading branch information
karyeet committed Jun 17, 2023
1 parent 49fa350 commit aafed63
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions general.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async function playNext(message) {
// set SC client id every start so it doesnt expire
let SC_clientId;
async function setScClientId() {
console.log("Refreshing soundcloud token");
SC_clientId = await playdl.getFreeClientID();

playdl.setToken({
Expand All @@ -118,8 +119,18 @@ async function setScClientId() {
// console.log("SC ID: " + SC_clientId);
}

async function refreshSpotifyToken() {
console.log("Refreshing spotify token");
if (playdl.is_expired()) {
await playdl.refreshToken();
}
}

setScClientId();
refreshSpotifyToken();
// set sc id every 10 minutes
setInterval(setScClientId, 10 * 60 * 1000);
// refresh spotify token every 55 minutes
setInterval(refreshSpotifyToken, 55 * 60 * 1000);

module.exports = { queue, audioPlayers, playNext, reactions, guildsMeta };

0 comments on commit aafed63

Please sign in to comment.