@discordjs/voice with @discordjs/next

I expected the audio to play, but it does not. No errors when running. I couldn't find the answer on GitHub, this server, or Google. Do I need to implement @discordjs/voice myself?
// (Let me know if it needs to be a working code)
import { GatewaySendPayload } from "@discordjs/core";
import {
DiscordGatewayAdapterLibraryMethods,
createAudioPlayer,
createAudioResource,
joinVoiceChannel,
} from "@discordjs/voice";
import { WebSocketManager } from "@discordjs/ws";

const connection = joinVoiceChannel({
adapterCreator: voiceAdapterCreator(channelId, gateway),
guildId,
channelId,
});
const resource = createAudioResource("./rickroll.mp3");
const player = createAudioPlayer();
const adapters = new Map();

player.play(resource);
connection.subscribe(player);

function voiceAdapterCreator(channelId: string, gateway: WebSocketManager) {
// from: https://github.com/discordjs/discord.js/blob/bfc7bb55641c60d4d67e57c27c9d1e63b6f30c9b/packages/discord.js/src/structures/Guild.js#L1410
return (methods: DiscordGatewayAdapterLibraryMethods) => {
adapters.set(channelId, methods);

return {
sendPayload: (data: GatewaySendPayload) => {
gateway.send(0, data);

return true;
},
destroy: () => {
adapters.delete(channelId);
},
};
};
}
// (Let me know if it needs to be a working code)
import { GatewaySendPayload } from "@discordjs/core";
import {
DiscordGatewayAdapterLibraryMethods,
createAudioPlayer,
createAudioResource,
joinVoiceChannel,
} from "@discordjs/voice";
import { WebSocketManager } from "@discordjs/ws";

const connection = joinVoiceChannel({
adapterCreator: voiceAdapterCreator(channelId, gateway),
guildId,
channelId,
});
const resource = createAudioResource("./rickroll.mp3");
const player = createAudioPlayer();
const adapters = new Map();

player.play(resource);
connection.subscribe(player);

function voiceAdapterCreator(channelId: string, gateway: WebSocketManager) {
// from: https://github.com/discordjs/discord.js/blob/bfc7bb55641c60d4d67e57c27c9d1e63b6f30c9b/packages/discord.js/src/structures/Guild.js#L1410
return (methods: DiscordGatewayAdapterLibraryMethods) => {
adapters.set(channelId, methods);

return {
sendPayload: (data: GatewaySendPayload) => {
gateway.send(0, data);

return true;
},
destroy: () => {
adapters.delete(channelId);
},
};
};
}
2 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
y
y5mo ago
Thank you! I'll give it a try I tried it, but it doesn't work as well as it should. I understand the cause. When acquiring an adapter, only undefined was returned. I fixed it and sent the data to @discordjs/voice, and the problem was resolved. I was able to solve it using this method. thank you.