No audio are played (no green circle)

so here's my command /play (currently the option is a path for a file but i have a code to get a video from yt based on name but it's not important here). The bot is simply not playing sound at all. Here are my files and the console log (i have debug option and i ran the command with the path to the file wich was correct)
No description
No description
4 Replies
d.js toolkit
d.js toolkit2w 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
Xalri
Xalri2w ago
└── discord.js@14.15.3 node v16.19.1 (can't use anything else) oh, my code lmao:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus } = require('@discordjs/voice');
const fs = require('fs');

module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Play audio in your voice channel')
.addStringOption(option =>
option.setName('audio')
.setDescription('Enter audio URL or name')
.setRequired(true)),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel;

if (!voiceChannel) {
return await interaction.reply('You need to be in a voice channel to use this command!');
}

const audioUrl = interaction.options.getString('audio');

const stream = fs.createReadStream(audioUrl);


try {
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
debug: true
});

connection.on(VoiceConnectionStatus.Ready, () => {
console.log(`Connected to ${voiceChannel.name}`);
});

connection.on(VoiceConnectionStatus.Disconnected, (error) => {
console.log(`Disconnected from ${voiceChannel.name}: ${error.message}`);
});

connection.on('debug', console.log)
connection.on('error', console.error);

const player = createAudioPlayer({
debug: true
});

player.on('debug', console.log)
player.on('error', console.error);

player.on(AudioPlayerStatus.Playing, () => {
console.log('Audio playback started');
});

stream.on('error', console.error);


player.on(AudioPlayerStatus.Idle, () => {
console.log('Audio playback finished');
connection.destroy();
});

const resource = createAudioResource(stream);
player.play(resource);

connection.subscribe(player);

await interaction.reply(`Now playing: ${audioUrl}`);
} catch (error) {
console.error('Error in play command:', error);
await interaction.reply('Failed to play the audio.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus } = require('@discordjs/voice');
const fs = require('fs');

module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Play audio in your voice channel')
.addStringOption(option =>
option.setName('audio')
.setDescription('Enter audio URL or name')
.setRequired(true)),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel;

if (!voiceChannel) {
return await interaction.reply('You need to be in a voice channel to use this command!');
}

const audioUrl = interaction.options.getString('audio');

const stream = fs.createReadStream(audioUrl);


try {
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
debug: true
});

connection.on(VoiceConnectionStatus.Ready, () => {
console.log(`Connected to ${voiceChannel.name}`);
});

connection.on(VoiceConnectionStatus.Disconnected, (error) => {
console.log(`Disconnected from ${voiceChannel.name}: ${error.message}`);
});

connection.on('debug', console.log)
connection.on('error', console.error);

const player = createAudioPlayer({
debug: true
});

player.on('debug', console.log)
player.on('error', console.error);

player.on(AudioPlayerStatus.Playing, () => {
console.log('Audio playback started');
});

stream.on('error', console.error);


player.on(AudioPlayerStatus.Idle, () => {
console.log('Audio playback finished');
connection.destroy();
});

const resource = createAudioResource(stream);
player.play(resource);

connection.subscribe(player);

await interaction.reply(`Now playing: ${audioUrl}`);
} catch (error) {
console.error('Error in play command:', error);
await interaction.reply('Failed to play the audio.');
}
},
};
? It's literally what rythm does? How is this a TOS violation?
duck
duck2w ago
streaming from youtube to discord violates youtube's tos, and by extension, discord's tos if you're familiar with rhythm, you should also hopefully know that this is exactly why rhythm shut down in the first place they no longer do this
Xalri
Xalri2w ago
so what is a TOS violation is to use youtube or spotify right? so if (as i said) i'm using a free mp3 file, it's not a TOS violation right? to be honest, i didn't know that and i think you missunderstood what i said. i was saying that i'll not use spotify or yt (they have api key and i don't understand a line of their doc anyway) . I'm intersting in this command tho because my brother make music so i think it can be cool to have custom music. pls help me with the command, i promise i won't use yt with my bot