Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

Mixed players from different instances #179

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function check(options: ManagerOptions) {
typeof options.clientName !== "string"
)
throw new TypeError('Manager option "clientName" must be a string.');

if (
typeof options.defaultSearchPlatform !== "undefined" &&
typeof options.defaultSearchPlatform !== "string"
Expand Down Expand Up @@ -419,7 +419,11 @@ export class Manager extends EventEmitter {
* @param options
*/
public create(options: PlayerOptions): Player {
options.manager = this; options.clientId = this.options.clientId;
if (this.players.has(options.guild)) {
if(this.players.get(options.guild).manager.options.clientId !== this.options.clientId) {
return new (Structure.get("Player"))(options);
}
return this.players.get(options.guild);
}

Expand Down Expand Up @@ -484,7 +488,7 @@ export class Manager extends EventEmitter {
} else {
/* voice state update */
if (update.user_id !== this.options.clientId) {
return;
return;
}

if (update.channel_id) {
Expand Down
15 changes: 13 additions & 2 deletions src/structures/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@ export class Player {
if (!this.manager) throw new RangeError("Manager has not been initiated.");

if (this.manager.players.has(options.guild)) {
return this.manager.players.get(options.guild);
if(this.manager.players.get(options.guild).manager.options.clientId === options.clientId) {
return this.manager.players.get(options.guild);
} else {
if(options.manager) this.manager = options.manager;
}
}

if(this.manager.options.clientId !== options.clientId) {
if(options.manager) this.manager = options.manager;
}
delete this.options.manager; delete this.options.clientId;
check(options);

this.guild = options.guild;
Expand Down Expand Up @@ -463,6 +470,10 @@ export interface PlayerOptions {
selfMute?: boolean;
/** If the player should deaf itself. */
selfDeafen?: boolean;
/** Client Id to check if no corruption is detected. */
clientId?: string;
/** Manager to set in case corruption is detected. */
manager?: Manager;
}

/** If track partials are set some of these will be `undefined` as they were removed. */
Expand Down