`<Player>.connect()` doesnt connect

Just trying to setup moonlink in my bot, made a quick command but it seems player.connect(...) doesn't connect or throw any errors? Code:
import { ApplicationCommandOptionType, type CommandInteraction, type GuildMember } from "discord.js";
import { Discord, Slash, SlashOption } from "discordx";
import { SurgeClient } from "../structures/SurgeClient.js";

@Discord()
export class Play {

@Slash({ description: "play" })
async play(@SlashOption({
description: "Song name / url",
name: "query",
required: true,
type: ApplicationCommandOptionType.String
}) query: string, interaction: CommandInteraction, client: SurgeClient) {
if (!interaction.guild) return;

const guildMember = interaction.member as GuildMember;

if (!guildMember.voice.channel) return interaction.reply({
content: `You are not on a voice channel`,
ephemeral: true
})

const player = client.moonlink.players.create({
guildId: interaction.guild.id,
voiceChannel: guildMember.voice.channel.id,
textChannel: interaction.channel!.id
})

if (!player.connected) player.connect({
setDeaf: true,
setMute: false
})

const queryResult = await client.moonlink.search(query)

if (queryResult.loadType == "error" || queryResult.loadType == "empty") {
return interaction.reply({
content: `Failed to find / load song from query: ${query}`
})
}

if (queryResult.loadType == "search") {
return interaction.reply("Not Implemented Yet.")
}

for (const track of queryResult.tracks) {
player.queue.add(track)
}

if (!player.playing) player.play()

interaction.reply("Playing")
}

}
import { ApplicationCommandOptionType, type CommandInteraction, type GuildMember } from "discord.js";
import { Discord, Slash, SlashOption } from "discordx";
import { SurgeClient } from "../structures/SurgeClient.js";

@Discord()
export class Play {

@Slash({ description: "play" })
async play(@SlashOption({
description: "Song name / url",
name: "query",
required: true,
type: ApplicationCommandOptionType.String
}) query: string, interaction: CommandInteraction, client: SurgeClient) {
if (!interaction.guild) return;

const guildMember = interaction.member as GuildMember;

if (!guildMember.voice.channel) return interaction.reply({
content: `You are not on a voice channel`,
ephemeral: true
})

const player = client.moonlink.players.create({
guildId: interaction.guild.id,
voiceChannel: guildMember.voice.channel.id,
textChannel: interaction.channel!.id
})

if (!player.connected) player.connect({
setDeaf: true,
setMute: false
})

const queryResult = await client.moonlink.search(query)

if (queryResult.loadType == "error" || queryResult.loadType == "empty") {
return interaction.reply({
content: `Failed to find / load song from query: ${query}`
})
}

if (queryResult.loadType == "search") {
return interaction.reply("Not Implemented Yet.")
}

for (const track of queryResult.tracks) {
player.queue.add(track)
}

if (!player.playing) player.play()

interaction.reply("Playing")
}

}
10 Replies
MEE6
MEE6•2y ago
GG @Exzotic, you just advanced to level 1!
extended-salmon
extended-salmonOP•2y ago
ello ello 👀 ah nice, ill try setting volume not sure if i will release it just messing around really Just dont see why it wont connect yea ive done basically what it says with how ur suppose to connect etc but well I saw u forked it on ur github xD I wonder
1Lucas1.apk
1Lucas1.apk•2y ago
Hello Apologies for the delay Well, a question how you put spayload in the moonlink.js constructor Builder's last option Could you provide me with that part?
extended-salmon
extended-salmonOP•2y ago
this.moonlink = new MoonlinkManager([
{
host: "REDACTED",
port: 2333,
password: process.env.LAVALINK_PASSWORD as string
}
], {}, (guild: string, sPayload: any) => this.guilds.cache.get(guild)?.shard.send(sPayload))

this.on("raw", (data: any) => { this.moonlink.packetUpdate(data) })
this.moonlink = new MoonlinkManager([
{
host: "REDACTED",
port: 2333,
password: process.env.LAVALINK_PASSWORD as string
}
], {}, (guild: string, sPayload: any) => this.guilds.cache.get(guild)?.shard.send(sPayload))

this.on("raw", (data: any) => { this.moonlink.packetUpdate(data) })
Sure here it is
1Lucas1.apk
1Lucas1.apk•2y ago
Which discord client package do you use?
this.moonlink = new MoonlinkManager([
{
host: "REDACTED",
port: 2333,
password: process.env.LAVALINK_PASSWORD as string
}
], {}, (guild: string, sPayload: any) => this.guilds.cache.get(guild)?.shard.send(JSON.parse(sPayload)))

this.on("raw", (data: any) => { this.moonlink.packetUpdate(data) })
this.moonlink = new MoonlinkManager([
{
host: "REDACTED",
port: 2333,
password: process.env.LAVALINK_PASSWORD as string
}
], {}, (guild: string, sPayload: any) => this.guilds.cache.get(guild)?.shard.send(JSON.parse(sPayload)))

this.on("raw", (data: any) => { this.moonlink.packetUpdate(data) })
extended-salmon
extended-salmonOP•2y ago
discordx / discord.js
MEE6
MEE6•2y ago
GG @Exzotic, you just advanced to level 2!
1Lucas1.apk
1Lucas1.apk•2y ago
done, solved A lot of times the object parse doesn't arrive in the package, you have to do it outside
extended-salmon
extended-salmonOP•2y ago
ah cool stuff, thanks for that
1Lucas1.apk
1Lucas1.apk•2y ago
Sorry, it's just that in this whole project, I'm the only one doing most things, it's kind of heavy, like documentation, support, updates, I still have school that weighs a little

Did you find this page helpful?