feat: add clearing cache to switchUser
This commit is contained in:
@@ -424,6 +424,13 @@ class Client extends BaseClient {
|
||||
*/
|
||||
async switchUser(options) {
|
||||
await this.logout();
|
||||
// There is a better way to code this but it's a temp fix - TheDevYellowy
|
||||
await this.clearCache(this.channels.cache);
|
||||
await this.clearCache(this.guilds.cache);
|
||||
await this.clearCache(this.relationships.cache);
|
||||
await this.clearCache(this.sessions.cache);
|
||||
await this.clearCache(this.users.cache);
|
||||
await this.clearCache(this.voiceStates.cache);
|
||||
if (typeof options == 'string') {
|
||||
await this.login(options);
|
||||
} else {
|
||||
@@ -570,6 +577,7 @@ class Client extends BaseClient {
|
||||
this.sweepers.destroy();
|
||||
this.ws.destroy();
|
||||
this.token = null;
|
||||
this.password = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -583,7 +591,7 @@ class Client extends BaseClient {
|
||||
voip_provider: null,
|
||||
},
|
||||
});
|
||||
this.destroy();
|
||||
await this.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -765,6 +773,16 @@ class Client extends BaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a cache
|
||||
* @param {Collection} cache The cache to clear
|
||||
*/
|
||||
async clearCache(cache) {
|
||||
await cache.forEach(async (V, K) => {
|
||||
await cache.delete(K);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweeps all text-based channels' messages and removes the ones older than the max message lifetime.
|
||||
* If the message has been edited, the time of the edit is used rather than the time of the original message.
|
||||
|
Reference in New Issue
Block a user