I tried to play ogg but it doesn't play

although I can participate in the VC, the music does not play. There are no errors.
client.once('ready', async () => {
console.log('Ready!');
const guildId = '1236559277670531142';
const channelId = '1236989524903723028';
const loopUrl = 'https://cdn.glitch.global/c2c4a2c3-b622-45de-81be-91a67ca39b93/Chill-beats-lofi-hiphop-mix-__-study_chill_stay-home-playlist%E3%80%90night-lullaby% E3%80%91.ogg?v=1715028861751';
const guild = await client.guilds.fetch(guildId);
if (!guild) return console.error('Guild not found.');
const channel = guild.channels.cache.get(channelId);
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
});
connection.on('error', console.error);
connection.on('stateChange', (oldState, newState) => {
if (newState.status === 'idle') {
connection.play(createAudioResource(loopUrl));
}
});
});
client.once('ready', async () => {
console.log('Ready!');
const guildId = '1236559277670531142';
const channelId = '1236989524903723028';
const loopUrl = 'https://cdn.glitch.global/c2c4a2c3-b622-45de-81be-91a67ca39b93/Chill-beats-lofi-hiphop-mix-__-study_chill_stay-home-playlist%E3%80%90night-lullaby% E3%80%91.ogg?v=1715028861751';
const guild = await client.guilds.fetch(guildId);
if (!guild) return console.error('Guild not found.');
const channel = guild.channels.cache.get(channelId);
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
});
connection.on('error', console.error);
connection.on('stateChange', (oldState, newState) => {
if (newState.status === 'idle') {
connection.play(createAudioResource(loopUrl));
}
});
});
17 Replies
d.js toolkit
d.js toolkit8mo 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!
ShompiFlen
ShompiFlen8mo ago
Can you please log the statechanges? also what intents are you using currently?
! はげたこ
! はげたこOP8mo ago
const { AttachmentBuilder , ChannelType , Client, GatewayIntentBits, EmbedBuilder, Partials, ActivityType, ChannelSelectMenuBuilder, ActionRowBuilder, WebhookClient, PermissionsBitField, Permission } = require("discord.js");
const {StreamType, createAudioPlayer, createAudioResource, joinVoiceChannel, getVoiceConnection } = require('@discordjs/voice');


const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations, GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessageReactions, GatewayIntentBits.MessageContent],
partials: [Partials.User, Partials.Channel, Partials.GuildMember, Partials.Message, Partials.Reaction]
});
const { AttachmentBuilder , ChannelType , Client, GatewayIntentBits, EmbedBuilder, Partials, ActivityType, ChannelSelectMenuBuilder, ActionRowBuilder, WebhookClient, PermissionsBitField, Permission } = require("discord.js");
const {StreamType, createAudioPlayer, createAudioResource, joinVoiceChannel, getVoiceConnection } = require('@discordjs/voice');


const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations, GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessageReactions, GatewayIntentBits.MessageContent],
partials: [Partials.User, Partials.Channel, Partials.GuildMember, Partials.Message, Partials.Reaction]
});
I checked the console.log for state changes
State changed from signaling to connecting
State changed from connecting to connecting
State changed from connecting to connecting
State changed from connecting to connecting
State changed from connecting to ready
State changed from signaling to connecting
State changed from connecting to connecting
State changed from connecting to connecting
State changed from connecting to connecting
State changed from connecting to ready
For some reason the sound isn't playing
ShompiFlen
ShompiFlen8mo ago
pretty sure you have yo create an audio player for this iirc let me check
! はげたこ
! はげたこOP8mo ago
got it. thank you. 👍
ShompiFlen
ShompiFlen8mo ago
yea you need an audio player to play audio over the connection,
! はげたこ
! はげたこOP8mo ago
Would you like to know more?
ShompiFlen
ShompiFlen8mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
! はげたこ
! はげたこOP8mo ago
I will check it. thank you. I changed the code like this, but it still doesn't play;
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});

client.once('ready', async () => {
console.log('Ready!');
const guildId = '1236559277670531142';
const channelId = '1236989524903723028';
const loopUrl = 'https://cdn.glitch.global/c2c4a2c3-b622-45de-81be-91a67ca39b93/Chill-beats-lofi-hiphop-mix-__-study_chill_stay-home-playlist%E3%80%90night-lullaby% E3%80%91.ogg?v=1715028861751';
const guild = await client.guilds.fetch('1236559277670531142');
const connection = joinVoiceChannel({
adapterCreator: guild.voiceAdapterCreator,
});

connection.subscribe(player);
});

player.on(AudioPlayerStatus.Idle, () => {
console.log('Idle state detected. Playing audio...');
const loopUrl = 'https://cdn.glitch.global/c2c4a2c3-b622-45de-81be-91a67ca39b93/Chill-beats-lofi-hiphop-mix-__-study_chill_stay-home-playlist%E3%80%90night-lullaby% E3%80%91.ogg?v=1715028861751';
const resource = createAudioResource(loopUrl);
player.play(resource);
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});

client.once('ready', async () => {
console.log('Ready!');
const guildId = '1236559277670531142';
const channelId = '1236989524903723028';
const loopUrl = 'https://cdn.glitch.global/c2c4a2c3-b622-45de-81be-91a67ca39b93/Chill-beats-lofi-hiphop-mix-__-study_chill_stay-home-playlist%E3%80%90night-lullaby% E3%80%91.ogg?v=1715028861751';
const guild = await client.guilds.fetch('1236559277670531142');
const connection = joinVoiceChannel({
adapterCreator: guild.voiceAdapterCreator,
});

connection.subscribe(player);
});

player.on(AudioPlayerStatus.Idle, () => {
console.log('Idle state detected. Playing audio...');
const loopUrl = 'https://cdn.glitch.global/c2c4a2c3-b622-45de-81be-91a67ca39b93/Chill-beats-lofi-hiphop-mix-__-study_chill_stay-home-playlist%E3%80%90night-lullaby% E3%80%91.ogg?v=1715028861751';
const resource = createAudioResource(loopUrl);
player.play(resource);
});
😢 console.log('Idle state detected. Playing audio...'); will not be displayed forever
ShompiFlen
ShompiFlen8mo ago
can you try removing the ?v= query parameter from the ogg url? just copy it until the .ogg
! はげたこ
! はげたこOP8mo ago
thank you for your reply It doesn't play even if I change the code as below
client.once('ready', async () => {
console.log('Ready!');
const guild = await client.guilds.fetch('1236559277670531142');
const channel = client.channels.cache.get('1236989524903723028');
const connection = joinVoiceChannel({
channelId: '1236989524903723028',
guildId: '1236559277670531142',
adapterCreator: channel.guild.voiceAdapterCreator
});
connection.subscribe(player);
});

player.on(AudioPlayerStatus.Idle, () => {
console.log('Idle state detected. Playing audio...');
const loopUrl = 'https://cdn.glitch.global/c2c4a2c3-b622-45de-81be-91a67ca39b93/Chill-beats-lofi-hiphop-mix-__-study_chill_stay-home-playlist%E3%80%90night-lullaby% E3%80%91.ogg';
const resource = createAudioResource(loopUrl);
player.play(resource);
});
client.once('ready', async () => {
console.log('Ready!');
const guild = await client.guilds.fetch('1236559277670531142');
const channel = client.channels.cache.get('1236989524903723028');
const connection = joinVoiceChannel({
channelId: '1236989524903723028',
guildId: '1236559277670531142',
adapterCreator: channel.guild.voiceAdapterCreator
});
connection.subscribe(player);
});

player.on(AudioPlayerStatus.Idle, () => {
console.log('Idle state detected. Playing audio...');
const loopUrl = 'https://cdn.glitch.global/c2c4a2c3-b622-45de-81be-91a67ca39b93/Chill-beats-lofi-hiphop-mix-__-study_chill_stay-home-playlist%E3%80%90night-lullaby% E3%80%91.ogg';
const resource = createAudioResource(loopUrl);
player.play(resource);
});
😢
ShompiFlen
ShompiFlen8mo ago
do you have ffmpeg and other dependencies installed? can you show your package.json file?
! はげたこ
! はげたこOP8mo ago
{
"name": "Discord-js-v14-template-for-glitch",
"version": "14",
"description": "It is template of Discord.js v14.",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"discord.js": "^14.13.0",
"canvacord": "^5.4.10",
"canvas": "^2.11.2",
"fs": "^0.0.2",
"discord-welcome-card": "^4.9.3",
"@discordjs/voice": "^0.17.0",
"libsodium-wrappers": "^0.7.13",
"ffmpeg": "^0.0.4"
},
"engines": {
"node": "16.x"
},
"repository": {
"url": "https://glitch.com/edit/#!/discord-js-v14-template-glitch"
},
"license": "MIT",
"keywords": [
"node",
"glitch",
"template"
]
}
{
"name": "Discord-js-v14-template-for-glitch",
"version": "14",
"description": "It is template of Discord.js v14.",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"discord.js": "^14.13.0",
"canvacord": "^5.4.10",
"canvas": "^2.11.2",
"fs": "^0.0.2",
"discord-welcome-card": "^4.9.3",
"@discordjs/voice": "^0.17.0",
"libsodium-wrappers": "^0.7.13",
"ffmpeg": "^0.0.4"
},
"engines": {
"node": "16.x"
},
"repository": {
"url": "https://glitch.com/edit/#!/discord-js-v14-template-glitch"
},
"license": "MIT",
"keywords": [
"node",
"glitch",
"template"
]
}
ShompiFlen
ShompiFlen8mo ago
dont install ffmpeg through npm
! はげたこ
! はげたこOP8mo ago
ok
d.js docs
d.js docs8mo ago
- npm: npm install ffmpeg-static - Install: Download | chocolatey | homebrew | your distributions package manager - Tutorial: YouTube - ffmpeg-binaries is deprecated, uninstall it with npm rm ffmpeg-binaries
ThePedroo
ThePedroo8mo ago
or use a FFmpeg installation Prefferably create a HTTP stream without djs/voice and pipe to djs/voice If anything, log the state changes once again and send them here
Want results from more Discord servers?
Add your server