Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: requesterBy.userData does not exist, and players did not change status to playing false when disconnecting from the node #131

Merged
merged 4 commits into from
Jan 11, 2025
Merged
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
5 changes: 5 additions & 0 deletions dist/src/entities/Node.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/entities/Node.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/src/entities/Player.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export declare class Player {
disconnect(): boolean;
play(options?: {
encoded?: string;
requestedBy?: {
userData: any;
requestedBy?: string | {
id?: any;
userData?: any;
};
position?: number;
endTime?: number;
Expand Down
10 changes: 5 additions & 5 deletions dist/src/entities/Player.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/entities/Player.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moonlink.js",
"version": "4.4.6",
"version": "4.4.7",
"description": "Imagine a Music... 🌙✨ Welcome to Moonlink.js! We invite you to create your own music bot on Discord using Lavalink, in a simple and easy way! 🎶🤖",
"keywords": [
"bot",
Expand Down
7 changes: 7 additions & 0 deletions src/entities/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export class Node {
this.connect();
}, this.retryDelay);

if (this.getPlayersCount > 0) {
this.getPlayers().forEach(player => {
player.playing = false;
});
}

if (this.getPlayersCount > 0 && this.manager.options.movePlayersOnReconnect) {
let node = this.manager.nodes.sortByUsage(this.manager.options.sortTypeNode || "players");
if (!node) {
Expand Down Expand Up @@ -136,6 +142,7 @@ export class Node {
this.identifier ? this.identifier : this.address
}) has disconnected with code ${code} and reason ${reason}.`
);

this.manager.emit("nodeDisconnect", this, code, reason);
}
protected async message({ data }): Promise<void> {
Expand Down
12 changes: 6 additions & 6 deletions src/entities/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class Player {
public async play(
options: {
encoded?: string;
requestedBy?: { userData: any };
requestedBy?: string | { id?: any; userData?: any };
position?: number;
endTime?: number;
} = {}
Expand All @@ -179,11 +179,11 @@ export class Player {
}

if (
typeof options.requestedBy.userData == "string" ||
typeof this.current.requestedBy.userData == "string"
typeof options.requestedBy == "string" ||
typeof this.current.requestedBy?.userData == "string"
) {
options.requestedBy.userData = {
id: options.requestedBy.userData ?? this.current.requestedBy.userData,
options.requestedBy = {
id: options.requestedBy as string ?? this.current?.requestedBy.userData as string,
};
}

Expand All @@ -199,7 +199,7 @@ export class Player {
track: {
encoded: this.current.encoded,
userData:
options.requestedBy?.userData ?? this.current?.requestedBy?.userData ?? undefined,
options.requestedBy ?? this.current?.requestedBy ?? undefined,
},
position: options.position ?? 0,
endTime: options.endTime ?? undefined,
Expand Down
6 changes: 3 additions & 3 deletions testBot/bot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require("discord.js");
const { Manager } = require("../dist/index.js");
const { Manager, decodeTrack } = require("../dist/index.js");
const fs = require("fs");
require("dotenv").config();

Expand All @@ -20,7 +20,7 @@ client.manager = new Manager({
secure: false,
port: 3010,
password: "pwd",
},
}
],
options: {
clientName: "TRISTAR/1.1",
Expand Down Expand Up @@ -75,5 +75,5 @@ client.once("ready", () => {
client.manager.on("debug", msg => console.log("[DEBUG]:", msg));
client.on("raw", d => client.manager.packetUpdate(d));
client.on("messageCreate", message => handleCommand(client, message));

console.log(decodeTrack("QAAAAAMAHyhGUkVFKSBSJkIgdHlwZSBCZWF0IC0gIlNoaXZlciIADUN5Y2xvcGUgQmVhdHoAAAAAAAKrmAALZDE5aWVhR2ttdUkAAQAraHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kMTlpZWFHa211SQEAMGh0dHBzOi8vaS55dGltZy5jb20vdmkvZDE5aWVhR2ttdUkvbXFkZWZhdWx0LmpwZwAAB3lvdXR1YmUAAAAAAAAAAA=="))
client.login(process.env.TOKEN).catch(console.error);
2 changes: 1 addition & 1 deletion testBot/commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
const searchResult = await client.manager.search({ query: args.join(" ") });
if (!searchResult.tracks.length) return message.reply("No results found.");

player.queue.add(searchResult.tracks[0]);
player.queue.add(searchResult.tracks[0], message.author.id);
if (!player.playing) player.play();
await message.reply(`Playing track: ${searchResult.tracks[0].title}`);
},
Expand Down