not playing

the bot is not playing the song, this is my play.js
const Discord = require('discord.js');
const config = require('../../config.json');
const { S, getUserData } = require("lavaclient");

module.exports = {
name: "Play",
aliases: ["P", "start"],
description: "Plays song for you.",
memberVoice: true,
botVoice: false,
sameVoice: true,
queueNeeded: false,

async execute(client, message, args, cmd, memberVC, botVC, queue) {

const string = args.join(' ');
if (!string) {

const stringEmbed = new Discord.EmbedBuilder()
.setColor(config.ErrorColor)
.setDescription("Please enter a song url or query to search.")
.setFooter({
text: `Commanded by ${message.author.tag}`,
iconURL: message.author.displayAvatarURL({ size: 1024 })
});

return await message.reply({ embeds: [stringEmbed] });

};

try {

let player = await client.lavaclient.players.resolve(message.guild.id);

if (!player) {
player = await client.lavaclient.players.create(message.guild.id);
}

player.channel = message.channel;

player.voice.connect(memberVC);

const results = await client.lavaclient.api.loadTracks("ytsearch:never gonna give you up");

const track = results.data[0];

await player.play({
encoded: track.encoded,
userData: { requesterId: message.author.id },
});

} catch (error) {

console.log(error);

const errorEmbed = new Discord.EmbedBuilder()
.setColor(config.ErrorColor)
.setDescription(error.message.length > 4096 ? error.message.slice(0, 4093) + "..." : error.message)
.setFooter({
text: `Commanded by ${message.author.tag}`,
iconURL: message.author.displayAvatarURL({ size: 1024 })
});

return await message.reply({ embeds: [errorEmbed] });

};

},

};
const Discord = require('discord.js');
const config = require('../../config.json');
const { S, getUserData } = require("lavaclient");

module.exports = {
name: "Play",
aliases: ["P", "start"],
description: "Plays song for you.",
memberVoice: true,
botVoice: false,
sameVoice: true,
queueNeeded: false,

async execute(client, message, args, cmd, memberVC, botVC, queue) {

const string = args.join(' ');
if (!string) {

const stringEmbed = new Discord.EmbedBuilder()
.setColor(config.ErrorColor)
.setDescription("Please enter a song url or query to search.")
.setFooter({
text: `Commanded by ${message.author.tag}`,
iconURL: message.author.displayAvatarURL({ size: 1024 })
});

return await message.reply({ embeds: [stringEmbed] });

};

try {

let player = await client.lavaclient.players.resolve(message.guild.id);

if (!player) {
player = await client.lavaclient.players.create(message.guild.id);
}

player.channel = message.channel;

player.voice.connect(memberVC);

const results = await client.lavaclient.api.loadTracks("ytsearch:never gonna give you up");

const track = results.data[0];

await player.play({
encoded: track.encoded,
userData: { requesterId: message.author.id },
});

} catch (error) {

console.log(error);

const errorEmbed = new Discord.EmbedBuilder()
.setColor(config.ErrorColor)
.setDescription(error.message.length > 4096 ? error.message.slice(0, 4093) + "..." : error.message)
.setFooter({
text: `Commanded by ${message.author.tag}`,
iconURL: message.author.displayAvatarURL({ size: 1024 })
});

return await message.reply({ embeds: [errorEmbed] });

};

},

};
42 Replies
arpos
arposOP8mo ago
@gino @Lupine
Lupine
Lupine8mo ago
This is not very helpful, can you expand on what exactly you mean by the bot is not playing the song. Is it joining the channel and sitting in silence? Is it not joining the channel at all? Do you have any logs that may or may not suggest why the bot is not playing from both Lavaclient and Lavalink?
arpos
arposOP8mo ago
the bot is joining the voice channel but not playing anything, This is the logs from lavalink
2024-05-01T09:14:37.197Z INFO 385016 --- [ XNIO-1 task-2] l.server.player.AudioLoaderRestHandler : Got request to load for identifier "ytsearch:never gonna give you up"
2024-05-01T09:14:37.800Z INFO 385016 --- [ XNIO-1 task-2] lavalink.server.player.AudioLoader : Loaded playlist Search results for: never gonna give you up
2024-05-01T09:14:37.881Z INFO 385016 --- [ XNIO-1 task-2] l.server.io.RequestLoggingFilter : GET /v4/loadtracks?identifier=ytsearch%3Anever+gonna+give+you+up&trace=true, client=127.0.0.1
2024-05-01T09:14:38.644Z WARN 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : YouTube auth tokens can't be retrieved because email and password is not set in YoutubeAudioSourceManager, age restricted videos will throw exceptions.
2024-05-01T09:14:38.737Z INFO 385016 --- [ XNIO-1 task-2] l.server.io.RequestLoggingFilter : PATCH /v4/sessions/nnva9slej7piiac6/players/1227852145404153917?noReplace=false&trace=true, client=127.0.0.1, payload={"track":{"encoded":"QAAA2QMAPFJpY2sgQXN0bGV5IC0gTmV2ZXIgR29ubmEgR2l2ZSBZb3UgVXAgKE9mZmljaWFsIE11c2ljIFZpZGVvKQALUmljayBBc3RsZXkAAAAAAANACAALZFF3NHc5V2dYY1EAAQAraHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQEANGh0dHBzOi8vaS55dGltZy5jb20vdmkvZFF3NHc5V2dYY1EvbWF4cmVzZGVmYXVsdC5qcGcAAAd5b3V0dWJlAAAAAAAAAAA=","userData":{"requesterId":"935495393230344243"}}}
2024-05-01T09:14:39.411Z INFO 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : Updating YouTube visitor id (current is null).
2024-05-01T09:14:39.472Z INFO 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : Updating YouTube visitor id succeeded, new one is CgtOYTlnOWE2MFZVOCj_j8ixBjIKCgJVUxIEGgAgQzoMCAEg-6Soivf_gZlm, next update will be after 600 seconds.
2024-05-01T09:14:37.197Z INFO 385016 --- [ XNIO-1 task-2] l.server.player.AudioLoaderRestHandler : Got request to load for identifier "ytsearch:never gonna give you up"
2024-05-01T09:14:37.800Z INFO 385016 --- [ XNIO-1 task-2] lavalink.server.player.AudioLoader : Loaded playlist Search results for: never gonna give you up
2024-05-01T09:14:37.881Z INFO 385016 --- [ XNIO-1 task-2] l.server.io.RequestLoggingFilter : GET /v4/loadtracks?identifier=ytsearch%3Anever+gonna+give+you+up&trace=true, client=127.0.0.1
2024-05-01T09:14:38.644Z WARN 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : YouTube auth tokens can't be retrieved because email and password is not set in YoutubeAudioSourceManager, age restricted videos will throw exceptions.
2024-05-01T09:14:38.737Z INFO 385016 --- [ XNIO-1 task-2] l.server.io.RequestLoggingFilter : PATCH /v4/sessions/nnva9slej7piiac6/players/1227852145404153917?noReplace=false&trace=true, client=127.0.0.1, payload={"track":{"encoded":"QAAA2QMAPFJpY2sgQXN0bGV5IC0gTmV2ZXIgR29ubmEgR2l2ZSBZb3UgVXAgKE9mZmljaWFsIE11c2ljIFZpZGVvKQALUmljayBBc3RsZXkAAAAAAANACAALZFF3NHc5V2dYY1EAAQAraHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQEANGh0dHBzOi8vaS55dGltZy5jb20vdmkvZFF3NHc5V2dYY1EvbWF4cmVzZGVmYXVsdC5qcGcAAAd5b3V0dWJlAAAAAAAAAAA=","userData":{"requesterId":"935495393230344243"}}}
2024-05-01T09:14:39.411Z INFO 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : Updating YouTube visitor id (current is null).
2024-05-01T09:14:39.472Z INFO 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : Updating YouTube visitor id succeeded, new one is CgtOYTlnOWE2MFZVOCj_j8ixBjIKCgJVUxIEGgAgQzoMCAEg-6Soivf_gZlm, next update will be after 600 seconds.
Lupine
Lupine8mo ago
Have you configured your voice state/server update events properly?
Lupine
Lupine8mo ago
No description
arpos
arposOP8mo ago
I don't know lol, I am new to this music thing, are you referring to this
client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
Lupine
Lupine8mo ago
Yes, whatever your method is for handling events, you will need to listen to VoiceServerUpdate and VoiceStateUpdate and pass the data from the event into Node#handleVoiceUpdate
arpos
arposOP8mo ago
Oh, this is my index.js
require('dotenv').config();
const Discord = require('discord.js');
const fs = require('node:fs');
const { MUSIC_BOT_TOKEN_DEV } = process.env;
const { saveProcess } = require('../../lib/botProcess');

const { Node } = require("lavaclient");

// Discord Client Constructor
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent,
],
});

const info = {
host: "2.tcp.ngrok.io",
port: 13497,
auth: "youshallnotpass"
};

client.lavaclient = new Node({
info,
ws: {
// userId: '1227853247243616297',
clientName: "my very cool bot",
resuming: false | { timeout: 30_000 },
reconnecting: {
tries: 3,
delay: (attempt) => attempt * 1_000
}
},
rest: {
enableTrace: true,
fetch: fetch,
userAgent: "my very cool bot (v1.0.0, <user id>)"
},
discord: {
sendGatewayCommand: (id, payload) => {
const guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
userId: '1227853247243616297'
}
});


// Events and commands handling


client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));

// Discord Client login
client.login(process.argv[2] ?? MUSIC_BOT_TOKEN_DEV);
saveProcess(process.env.pm_id, process.argv[3], process.argv[2] ?? MUSIC_BOT_TOKEN_DEV);
require('dotenv').config();
const Discord = require('discord.js');
const fs = require('node:fs');
const { MUSIC_BOT_TOKEN_DEV } = process.env;
const { saveProcess } = require('../../lib/botProcess');

const { Node } = require("lavaclient");

// Discord Client Constructor
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent,
],
});

const info = {
host: "2.tcp.ngrok.io",
port: 13497,
auth: "youshallnotpass"
};

client.lavaclient = new Node({
info,
ws: {
// userId: '1227853247243616297',
clientName: "my very cool bot",
resuming: false | { timeout: 30_000 },
reconnecting: {
tries: 3,
delay: (attempt) => attempt * 1_000
}
},
rest: {
enableTrace: true,
fetch: fetch,
userAgent: "my very cool bot (v1.0.0, <user id>)"
},
discord: {
sendGatewayCommand: (id, payload) => {
const guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
userId: '1227853247243616297'
}
});


// Events and commands handling


client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));

// Discord Client login
client.login(process.argv[2] ?? MUSIC_BOT_TOKEN_DEV);
saveProcess(process.env.pm_id, process.argv[3], process.argv[2] ?? MUSIC_BOT_TOKEN_DEV);
but the bot is still not playing anything @Lupine
client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (u) => client.lavaclient.players.handleVoiceUpdate(u));
Is this just a template or it is an working example, if not, can I get some working example codes for handleVoiceUpdate()
Lupine
Lupine8mo ago
What is your method for handling events currently? For example your message event All you need to do is listen to the VoiceStateUpdate and VoiceServerUpdate events using the same method and pass the data into the handleVoiceUpdate method
arpos
arposOP8mo ago
this is my messageCreate.js
module.exports = {
name: Events.MessageCreate,
execute: async (client, message) => {
// Checking some stuffs

if ((message.content.toLowerCase().startsWith(config.Prefix) && messageInChannel) botTagged) {
if (
!message.channel
.permissionsFor(message.guild.members.me)
.has(['ViewChannel', 'SendMessages', 'EmbedLinks', 'ReadMessageHistory'])
)
return;


const args = message.content.slice(config.Prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command =
client.MessageCommands.get(args[0])
client.MessageCommands.find((c) => c.aliases && c.aliases.map((a) => a.toLowerCase()).includes(args[0]));
if (command) {
const memberVC = message.member.voice.channel null;
const botVC = message.guild.members.me.voice.channel null;

if (command.memberVoice) {
if (!memberVC) {
return await message.reply("You aren't connected to any Voice Channel.");
}
}

if (command.botVoice) {
if (!botVC) {
return await message.reply("I'm not connected to any Voice Chnanel.");
}
}

if (command.sameVoice) {
if (memberVC && botVC && memberVC.id !== botVC.id) {
return await message.reply("You aren't connected to my Voice Channel.");
}
}

try {
command.execute(client, message, args, cmd, memberVC, botVC);
} catch (error) {
return await message.reply({ embeds: [errorEmbed] });
}
}
}
},
};
module.exports = {
name: Events.MessageCreate,
execute: async (client, message) => {
// Checking some stuffs

if ((message.content.toLowerCase().startsWith(config.Prefix) && messageInChannel) botTagged) {
if (
!message.channel
.permissionsFor(message.guild.members.me)
.has(['ViewChannel', 'SendMessages', 'EmbedLinks', 'ReadMessageHistory'])
)
return;


const args = message.content.slice(config.Prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command =
client.MessageCommands.get(args[0])
client.MessageCommands.find((c) => c.aliases && c.aliases.map((a) => a.toLowerCase()).includes(args[0]));
if (command) {
const memberVC = message.member.voice.channel null;
const botVC = message.guild.members.me.voice.channel null;

if (command.memberVoice) {
if (!memberVC) {
return await message.reply("You aren't connected to any Voice Channel.");
}
}

if (command.botVoice) {
if (!botVC) {
return await message.reply("I'm not connected to any Voice Chnanel.");
}
}

if (command.sameVoice) {
if (memberVC && botVC && memberVC.id !== botVC.id) {
return await message.reply("You aren't connected to my Voice Channel.");
}
}

try {
command.execute(client, message, args, cmd, memberVC, botVC);
} catch (error) {
return await message.reply({ embeds: [errorEmbed] });
}
}
}
},
};
the only files that have music codes are index.js and play.js as of now, for testing
Lupine
Lupine8mo ago
Right, so you can create something similar for VoiceStateUpdate and VoiceServerUpdate and simply pass the parameter from your execute method into the handleVoiceUpdate method on the Node
import { WebSocketEvent } from "../../lib/extensions/Event";
import { logger } from "../../index";
import { client } from "../../index";

export default new WebSocketEvent("VOICE_SERVER_UPDATE", data => {
logger.info(`[WebSocket] Voice server update received... handling`);
client.lavalink?.handleVoiceUpdate(data);
})
import { WebSocketEvent } from "../../lib/extensions/Event";
import { logger } from "../../index";
import { client } from "../../index";

export default new WebSocketEvent("VOICE_SERVER_UPDATE", data => {
logger.info(`[WebSocket] Voice server update received... handling`);
client.lavalink?.handleVoiceUpdate(data);
})
This is how I do it, but you should note that you cannot copy and paste this because I handle events differently But the premise is the same. I listen to event, and pass the data from the event into the handleVoiceUpdate method I do the same for the VoiceStateUpdate event as well
arpos
arposOP8mo ago
alright, I will try it @Lupine , Hey , I did what you told me This is my VoiceStateUpdate.js, and similar is for VoiceServerUpdate,
const { Events, GatewayDispatchEvents } = require('discord.js');

module.exports = {
name: GatewayDispatchEvents.VoiceStateUpdate,
execute: async (client, data) => {

console.log("VoiceStateUpdate");
client.lavaclient.players.handleVoiceUpdate(data);
},
};
const { Events, GatewayDispatchEvents } = require('discord.js');

module.exports = {
name: GatewayDispatchEvents.VoiceStateUpdate,
execute: async (client, data) => {

console.log("VoiceStateUpdate");
client.lavaclient.players.handleVoiceUpdate(data);
},
};
And in index.js, I have listened to this event like this
const voiceStateUpdate = require('./WebSocketEvents/VoiceStateUpdate.js');
const voiceServerUpdate = require('./WebSocketEvents/VoiceServerUpdate.js');

client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (data) => {
// console.log("VoiceStateUpdate");
voiceStateUpdate.execute(client, data);
});
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (data) => {
// console.log("VoiceServerUpdate");
voiceServerUpdate.execute(client, data);
});
const voiceStateUpdate = require('./WebSocketEvents/VoiceStateUpdate.js');
const voiceServerUpdate = require('./WebSocketEvents/VoiceServerUpdate.js');

client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (data) => {
// console.log("VoiceStateUpdate");
voiceStateUpdate.execute(client, data);
});
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (data) => {
// console.log("VoiceServerUpdate");
voiceServerUpdate.execute(client, data);
});
But the bot is still not playing
Lupine
Lupine8mo ago
I dont understand how your bot is structured, to me this looks like you are listening to the event twice. Where is your event handler? how are you listening to the messageCreate event currently?
arpos
arposOP8mo ago
For the normal events, I have the event handler in index.js
// Event Handler
console.log('Loading Events');
const events = fs.readdirSync('./bots/music-bot/events/').filter((file) => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/${file}`);
// console.log(event);
// console.log(event.name);
client.on(file.split('.')[0], event.execute.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
}
// Event Handler
console.log('Loading Events');
const events = fs.readdirSync('./bots/music-bot/events/').filter((file) => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/${file}`);
// console.log(event);
// console.log(event.name);
client.on(file.split('.')[0], event.execute.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
}
and for the websocket events, I have also listened it it index.js but seperately
const voiceStateUpdate = require('./WebSocketEvents/VoiceStateUpdate.js');
const voiceServerUpdate = require('./WebSocketEvents/VoiceServerUpdate.js');

client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (data) => {
// console.log("VoiceStateUpdate");
voiceStateUpdate.execute(client, data);
});
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (data) => {
// console.log("VoiceServerUpdate");
voiceServerUpdate.execute(client, data);
});
const voiceStateUpdate = require('./WebSocketEvents/VoiceStateUpdate.js');
const voiceServerUpdate = require('./WebSocketEvents/VoiceServerUpdate.js');

client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (data) => {
// console.log("VoiceStateUpdate");
voiceStateUpdate.execute(client, data);
});
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (data) => {
// console.log("VoiceServerUpdate");
voiceServerUpdate.execute(client, data);
});
and the events for voice updates, are handeled seperately (last sent code block), it doesn't go on normal event handler (first sent code block)
Lupine
Lupine8mo ago
Put some log messages in the event. If the bot is sitting in silence its usually because these events are not setup correctly
arpos
arposOP8mo ago
Yeah, I did it and getting logs in the event. The events are properly listened
Lupine
Lupine8mo ago
Request a new song, and send logs for both Lavaclient and Lavalink
arpos
arposOP8mo ago
This is the logs from lavalink,
2024-05-01T11:46:22.915Z INFO 385016 --- [ XNIO-1 task-2] l.server.player.AudioLoaderRestHandler : Got request to load for identifier "ytsearch:despacito"
2024-05-01T11:46:23.303Z INFO 385016 --- [ XNIO-1 task-2] lavalink.server.player.AudioLoader : Loaded playlist Search results for: despacito
2024-05-01T11:46:23.307Z INFO 385016 --- [ XNIO-1 task-2] l.server.io.RequestLoggingFilter : GET /v4/loadtracks?identifier=ytsearch%3Adespacito&trace=true, client=127.0.0.1
2024-05-01T11:46:23.934Z INFO 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : Updating YouTube visitor id (current is CgtOa242RlFQdFo0byjVs8ixBjIKCgJVUxIEGgAgWToMCAEgw9qkytK6hplm).
2024-05-01T11:46:23.936Z INFO 385016 --- [ XNIO-1 task-2] l.server.io.RequestLoggingFilter : PATCH /v4/sessions/lt46xnybh100x77y/players/1227852145404153917?noReplace=false&trace=true, client=127.0.0.1, payload={"track":{"encoded":"QAAAwwMAJ0x1aXMgRm9uc2kgLSBEZXNwYWNpdG8gZnQuIERhZGR5IFlhbmtlZQAKTHVpcyBGb25zaQAAAAAABE2QAAtrSlFQN2tpdzVGawABACtodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWtKUVA3a2l3NUZrAQA0aHR0cHM6Ly9pLnl0aW1nLmNvbS92aS9rSlFQN2tpdzVGay9tYXhyZXNkZWZhdWx0LmpwZwAAB3lvdXR1YmUAAAAAAAAAAA==","userData":{"requesterId":"935495393230344243"}}}
2024-05-01T11:46:23.980Z INFO 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : Updating YouTube visitor id succeeded, new one is CgthVmVzcVM4aWVuTSiP18ixBjIKCgJVUxIEGgAgYjoMCAEg29Di5ffxiplm, next update will be after 600 seconds.
2024-05-01T11:46:22.915Z INFO 385016 --- [ XNIO-1 task-2] l.server.player.AudioLoaderRestHandler : Got request to load for identifier "ytsearch:despacito"
2024-05-01T11:46:23.303Z INFO 385016 --- [ XNIO-1 task-2] lavalink.server.player.AudioLoader : Loaded playlist Search results for: despacito
2024-05-01T11:46:23.307Z INFO 385016 --- [ XNIO-1 task-2] l.server.io.RequestLoggingFilter : GET /v4/loadtracks?identifier=ytsearch%3Adespacito&trace=true, client=127.0.0.1
2024-05-01T11:46:23.934Z INFO 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : Updating YouTube visitor id (current is CgtOa242RlFQdFo0byjVs8ixBjIKCgJVUxIEGgAgWToMCAEgw9qkytK6hplm).
2024-05-01T11:46:23.936Z INFO 385016 --- [ XNIO-1 task-2] l.server.io.RequestLoggingFilter : PATCH /v4/sessions/lt46xnybh100x77y/players/1227852145404153917?noReplace=false&trace=true, client=127.0.0.1, payload={"track":{"encoded":"QAAAwwMAJ0x1aXMgRm9uc2kgLSBEZXNwYWNpdG8gZnQuIERhZGR5IFlhbmtlZQAKTHVpcyBGb25zaQAAAAAABE2QAAtrSlFQN2tpdzVGawABACtodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWtKUVA3a2l3NUZrAQA0aHR0cHM6Ly9pLnl0aW1nLmNvbS92aS9rSlFQN2tpdzVGay9tYXhyZXNkZWZhdWx0LmpwZwAAB3lvdXR1YmUAAAAAAAAAAA==","userData":{"requesterId":"935495393230344243"}}}
2024-05-01T11:46:23.980Z INFO 385016 --- [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker : Updating YouTube visitor id succeeded, new one is CgthVmVzcVM4aWVuTSiP18ixBjIKCgJVUxIEGgAgYjoMCAEg29Di5ffxiplm, next update will be after 600 seconds.
And I didn't got any error logs from from lavaclient, there is no logs after client ready log
Lupine
Lupine8mo ago
If there is no logs after the client ready log then that suggests your event isnt working Anytime someone mutes their client, joins a voice channel, leaves a voice channel etc. that event should fire
arpos
arposOP8mo ago
the custom logs is printing, like I put console.log("VoiceStateUpdate");, on VoiceStateUpdate event, like this,
const { Events, GatewayDispatchEvents } = require('discord.js');

module.exports = {
name: GatewayDispatchEvents.VoiceStateUpdate,
execute: async (client, data) => {
console.log("VoiceStateUpdate");
client.lavaclient.players.handleVoiceUpdate(data);
},
};
const { Events, GatewayDispatchEvents } = require('discord.js');

module.exports = {
name: GatewayDispatchEvents.VoiceStateUpdate,
execute: async (client, data) => {
console.log("VoiceStateUpdate");
client.lavaclient.players.handleVoiceUpdate(data);
},
};
"VoiceStateUpdate" is logging in the console.
[nodemon] restarting due to changes...
[nodemon] starting `node ./bots/music-bot`
Loading Events
Loading Message Commands
[2024-05-01 11:46:17] INFO: Ready! Logged in as Bot 0#7056
VoiceStateUpdate
VoiceServerUpdate
VoiceStateUpdate
[nodemon] restarting due to changes...
[nodemon] starting `node ./bots/music-bot`
Loading Events
Loading Message Commands
[2024-05-01 11:46:17] INFO: Ready! Logged in as Bot 0#7056
VoiceStateUpdate
VoiceServerUpdate
VoiceStateUpdate
Lupine
Lupine8mo ago
Right okay, its just a second ago you said you werent getting any logs after your ready event...
arpos
arposOP8mo ago
Yeah, lol. Sorry for confusion What to do next ?
Lupine
Lupine8mo ago
Try passing in the name of the event as a string "VOICE_SERVER_UPDATE" "VOICE_STATE_UPDATE" Im not sure if GatewayDispatchEvents.VoiceStateUpdate is a little different. This library requires using the raw updates
arpos
arposOP8mo ago
yeah, did it and still not playing :AHHHH:
Lupine
Lupine8mo ago
Listen to it via the client as well, you should be able to drop the ws property
arpos
arposOP8mo ago
I didn't understand
Lupine
Lupine8mo ago
You can listen to events directly from the client
client.on("VOICE_STATE_UPDATE", (d) => {
})
client.on("VOICE_STATE_UPDATE", (d) => {
})
arpos
arposOP8mo ago
Yeah, did it and still no result
Lupine
Lupine8mo ago
I still dont understand the structure of your bot? Why do you seemingly listen and handle your VoiceState and VoiceServer updates in your index file whilst also having a handler in seperate files?
arpos
arposOP8mo ago
I have this is my index.js
const voiceStateUpdate = require('./WebSocketEvents/VoiceStateUpdate.js');
const voiceServerUpdate = require('./WebSocketEvents/VoiceServerUpdate.js');

client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (data) => {
// console.log("VoiceStateUpdate");
voiceStateUpdate.execute(client, data);
});
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (data) => {
// console.log("VoiceServerUpdate");
voiceServerUpdate.execute(client, data);
});
const voiceStateUpdate = require('./WebSocketEvents/VoiceStateUpdate.js');
const voiceServerUpdate = require('./WebSocketEvents/VoiceServerUpdate.js');

client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (data) => {
// console.log("VoiceStateUpdate");
voiceStateUpdate.execute(client, data);
});
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (data) => {
// console.log("VoiceServerUpdate");
voiceServerUpdate.execute(client, data);
});
and in WebSocketEvents/VoiceStateUpdate.js, I have this, this is all codes in the file
const { Events, GatewayDispatchEvents } = require('discord.js');

module.exports = {
name: GatewayDispatchEvents.VoiceStateUpdate,
execute: async (client, data) => {
console.log("VoiceStateUpdate");
client.lavaclient.players.handleVoiceUpdate(data);
},
};
const { Events, GatewayDispatchEvents } = require('discord.js');

module.exports = {
name: GatewayDispatchEvents.VoiceStateUpdate,
execute: async (client, data) => {
console.log("VoiceStateUpdate");
client.lavaclient.players.handleVoiceUpdate(data);
},
};
and similar is for VoiceServerUpdate
Lupine
Lupine8mo ago
Im aware this is what you have Im just trying to wrap my head around why you appear to handle your other events differently Unless you havent been sending the full file each time
arpos
arposOP8mo ago
oh lol, I also have this is my index.js
// Event Handler
console.log('Loading Events');
const events = fs.readdirSync('./bots/music-bot/events/').filter((file) => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/${file}`);
// console.log(event);
// console.log(event.name);
client.on(file.split('.')[0], event.execute.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
}
// Event Handler
console.log('Loading Events');
const events = fs.readdirSync('./bots/music-bot/events/').filter((file) => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/${file}`);
// console.log(event);
// console.log(event.name);
client.on(file.split('.')[0], event.execute.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
}
Lupine
Lupine8mo ago
client.on(file.split('.')[0], event.execute.bind(null, client)); So you are listening to events more than once? If you have a file in there called VoiceServerUpdate. youll be listening to it more than once One) In this event handler code Two) In your index file from the previous code snippets you have sent
arpos
arposOP8mo ago
No, I don't have VoiceServerUpdate in there, this handler only handles the files in events folder, and I have VoiceServerUpdate in WebSocketEvents folder const events = fs.readdirSync('./bots/music-bot/events/').filter((file) I have event hander for both normal events and websocketevents in index.js
Lupine
Lupine8mo ago
Right, but without knowing the structure of your project, I cannot possibly know that In this message here: https://discord.com/channels/323365823572082690/1235136736351227914/1235178827416866827 you mentioned you had a file called VoiceStateUpdate.js
arpos
arposOP8mo ago
wait, I will send you the folder structure
Lupine
Lupine8mo ago
I can only assume that would be in your event folder as it matches the structure of your message event file
arpos
arposOP8mo ago
This is my folder structure
- root
|- commands
| |- play.js
| |- skip.js
| |- volume.js
| |- queue.js
|
|- events
| |- guildCreate.js
| |- interactionCreate.js
| |- messageCreate.js
| |- ready.js
|
|- utils
| |- components.js
| |- constants.js
| |- functions.js
| |- logger.js
| |- registerSlash.js
|
|- WebSocketEvents
| |- voiceServerUpdate.js
| |- voiceStateUpdate.js
|
|- index.js
|- README.md
|- express.js
|- config.json
- root
|- commands
| |- play.js
| |- skip.js
| |- volume.js
| |- queue.js
|
|- events
| |- guildCreate.js
| |- interactionCreate.js
| |- messageCreate.js
| |- ready.js
|
|- utils
| |- components.js
| |- constants.js
| |- functions.js
| |- logger.js
| |- registerSlash.js
|
|- WebSocketEvents
| |- voiceServerUpdate.js
| |- voiceStateUpdate.js
|
|- index.js
|- README.md
|- express.js
|- config.json
I have different handler for the files in events, and the files in WebSocketEvents, both in index.js ONE
const voiceStateUpdate = require('./WebSocketEvents/VoiceStateUpdate.js');
const voiceServerUpdate = require('./WebSocketEvents/VoiceServerUpdate.js');

client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (data) => {
// console.log("VoiceStateUpdate");
voiceStateUpdate.execute(client, data);
});
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (data) => {
// console.log("VoiceServerUpdate");
voiceServerUpdate.execute(client, data);
});
const voiceStateUpdate = require('./WebSocketEvents/VoiceStateUpdate.js');
const voiceServerUpdate = require('./WebSocketEvents/VoiceServerUpdate.js');

client.ws.on(Discord.GatewayDispatchEvents.VoiceStateUpdate, (data) => {
// console.log("VoiceStateUpdate");
voiceStateUpdate.execute(client, data);
});
client.ws.on(Discord.GatewayDispatchEvents.VoiceServerUpdate, (data) => {
// console.log("VoiceServerUpdate");
voiceServerUpdate.execute(client, data);
});
TWO
// Event Handler
console.log('Loading Events');
const events = fs.readdirSync('./bots/music-bot/events/').filter((file) => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/${file}`);
// console.log(event);
// console.log(event.name);
client.on(file.split('.')[0], event.execute.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
}
// Event Handler
console.log('Loading Events');
const events = fs.readdirSync('./bots/music-bot/events/').filter((file) => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/${file}`);
// console.log(event);
// console.log(event.name);
client.on(file.split('.')[0], event.execute.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
}
These both are in index.js, one handles the websocket events such as VoiceStateUpdate, VoiceServerUpdate, and two handles the normal events such as messageCreate, ready etc,
Lupine
Lupine8mo ago
In your client Have you considered that the guild might not have been cached yet? Where you define your node, in the sendGatewayPayload property. Try logging out the guild
arpos
arposOP8mo ago
const info = {
host: "2.tcp.ngrok.io",
port: 13497,
auth: "youshallnotpass"
};

client.lavaclient = new Node({
info,
ws: {
// userId: '1227853247243616297',
clientName: "my very cool bot",
resuming: false | { timeout: 30_000 },
reconnecting: {
tries: 3,
delay: (attempt) => attempt * 1_000
}
},
rest: {
enableTrace: true,
fetch: fetch,
userAgent: "my very cool bot (v1.0.0, <user id>)"
},
discord: {
sendGatewayCommand: (id, payload) => {
const guild = client.guilds.cache.get(id);
console.log(guild);
if (guild) guild.shard.send(payload);
},
userId: '1227853247243616297'
}
});
const info = {
host: "2.tcp.ngrok.io",
port: 13497,
auth: "youshallnotpass"
};

client.lavaclient = new Node({
info,
ws: {
// userId: '1227853247243616297',
clientName: "my very cool bot",
resuming: false | { timeout: 30_000 },
reconnecting: {
tries: 3,
delay: (attempt) => attempt * 1_000
}
},
rest: {
enableTrace: true,
fetch: fetch,
userAgent: "my very cool bot (v1.0.0, <user id>)"
},
discord: {
sendGatewayCommand: (id, payload) => {
const guild = client.guilds.cache.get(id);
console.log(guild);
if (guild) guild.shard.send(payload);
},
userId: '1227853247243616297'
}
});
it is logging out the guild,
<ref *2> Guild {
id: '1227852145404153917',
name: 'Airon Bot Test',
icon: null,
features: [],
commands: <ref *1> GuildApplicationCommandManager {
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: [Circular *2],
guildId: '1227852145404153917',
commandId: null
},
guild: [Circular *2]
},
// All other stuffs
}
<ref *2> Guild {
id: '1227852145404153917',
name: 'Airon Bot Test',
icon: null,
features: [],
commands: <ref *1> GuildApplicationCommandManager {
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: [Circular *2],
guildId: '1227852145404153917',
commandId: null
},
guild: [Circular *2]
},
// All other stuffs
}
@Lupine , is there anything we can do
Nansess
Nansess8mo ago
Quick question Are u able to play SoundCloud
arpos
arposOP8mo ago
how do I do that ? const results = await client.lavaclient.api.loadTracks("scsearch:never gonna give you up"); No, it is not playing soundcloud
Want results from more Discord servers?
Add your server