Nutchapol
Nutchapol
DIAdiscord.js - Imagine an app
Created by Nutchapol on 11/14/2024 in #djs-voice
Typescript complains about adapterCreator after upgrading to v0.17.0
i updated @discordjs/voice from 0.16.1 to 0.17.0 and discord.js from 14.14.1 to 14.16.3, and now this snippet makes typescript complains about
Type 'InternalDiscordGatewayAdapterCreator' is not assignable to type 'DiscordGatewayAdapterCreator'.
Types of parameters 'methods' and 'methods' are incompatible.
...
Type 'InternalDiscordGatewayAdapterCreator' is not assignable to type 'DiscordGatewayAdapterCreator'.
Types of parameters 'methods' and 'methods' are incompatible.
...
// for demonstration purposes only
import { joinVoiceChannel } from "@discordjs/voice"
import { Client, GatewayIntentBits } from "discord.js"

const client = new Client({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessageReactions,
],
})
await client.login("asdf")

const guild = await client.guilds.fetch("1234")
joinVoiceChannel({
guildId: guild.id,
channelId: "5678",
adapterCreator: guild.voiceAdapterCreator,
})
// for demonstration purposes only
import { joinVoiceChannel } from "@discordjs/voice"
import { Client, GatewayIntentBits } from "discord.js"

const client = new Client({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessageReactions,
],
})
await client.login("asdf")

const guild = await client.guilds.fetch("1234")
joinVoiceChannel({
guildId: guild.id,
channelId: "5678",
adapterCreator: guild.voiceAdapterCreator,
})
how do i fix this? are there changes i missed? the changelogs for voice 0.17.0 doesn't seem to mention anything about voice adapter creators
5 replies
DIAdiscord.js - Imagine an app
Created by Nutchapol on 3/30/2023 in #djs-voice
"Cannot perform IP discovery - socket closed"
getting this error after leaving the bot on for some time
file:///D:/musicbot/node_modules/@discordjs/voice/dist/index.mjs:286
this.socket.once("close", () => reject(new Error("Cannot perform IP discovery - socket closed")));
^

Error: Cannot perform IP discovery - socket closed
at Socket.<anonymous> (file:///D:/musicbot/node_modules/@discordjs/voice/dist/index.mjs:286:46)
at Object.onceWrapper (node:events:627:28)
at Socket.emit (node:events:525:35)
at socketCloseNT (node:dgram:754:8)
at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
Emitted 'error' event on VoiceConnection instance at:
at VoiceConnection.onNetworkingError (file:///D:/musicbot/node_modules/@discordjs/voice/dist/index.mjs:1403:10)
at Networking.emit (node:events:513:28)
at file:///D:/musicbot/node_modules/@discordjs/voice/dist/index.mjs:555:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
file:///D:/musicbot/node_modules/@discordjs/voice/dist/index.mjs:286
this.socket.once("close", () => reject(new Error("Cannot perform IP discovery - socket closed")));
^

Error: Cannot perform IP discovery - socket closed
at Socket.<anonymous> (file:///D:/musicbot/node_modules/@discordjs/voice/dist/index.mjs:286:46)
at Object.onceWrapper (node:events:627:28)
at Socket.emit (node:events:525:35)
at socketCloseNT (node:dgram:754:8)
at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
Emitted 'error' event on VoiceConnection instance at:
at VoiceConnection.onNetworkingError (file:///D:/musicbot/node_modules/@discordjs/voice/dist/index.mjs:1403:10)
at Networking.emit (node:events:513:28)
at file:///D:/musicbot/node_modules/@discordjs/voice/dist/index.mjs:555:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
is this piece of code below related to the error? (it's a fix for the "Music Bot stops playing after about 30-40 seconds" problem from another thread, although i changed from using Reflect.get to directly accessing properties)
voiceConnection.on('stateChange', (oldState, newState) => {
const oldNetworking = oldState.networking
const newNetworking = newState.networking

const networkStateChangeHandler = (
oldNetworkState,
newNetworkState
) => {
const newUdp = newNetworkState.udp
clearInterval(newUdp?.keepAliveInterval)
}

oldNetworking?.off('stateChange', networkStateChangeHandler)
newNetworking?.on('stateChange', networkStateChangeHandler)
})
voiceConnection.on('stateChange', (oldState, newState) => {
const oldNetworking = oldState.networking
const newNetworking = newState.networking

const networkStateChangeHandler = (
oldNetworkState,
newNetworkState
) => {
const newUdp = newNetworkState.udp
clearInterval(newUdp?.keepAliveInterval)
}

oldNetworking?.off('stateChange', networkStateChangeHandler)
newNetworking?.on('stateChange', networkStateChangeHandler)
})
currently using discord.js 14.7.1, @discordjs/voice 0.14.0, node 19.0.1
3 replies
DIAdiscord.js - Imagine an app
Created by Nutchapol on 3/29/2023 in #djs-questions
what's the boolean in Client<boolean>?
i'm using typescript and i see that Client is a generic type that takes a boolean (sub)class what can i do with that?
8 replies
DIAdiscord.js - Imagine an app
Created by Nutchapol on 2/12/2023 in #djs-voice
How do I stop an autopaused audio player?
title. it doesn't look like audioPlayer.stop() does anything its state doesn't change to idle too this prevents the bot from shutting itself down
5 replies
DIAdiscord.js - Imagine an app
Created by Nutchapol on 2/1/2023 in #djs-voice
what does joinVoiceChannel return when there's already an active voice connection?
so the guide says
If you try to call joinVoiceChannel on another channel in the same guild in which there is already an active voice connection, the existing voice connection switches over to the new channel.
does it return the same VoiceConnection object as before changing channels (therefore, it already has event listeners attached, if any) or is it a new VoiceConnection with the old one destroyed?
5 replies