#Trying to play an audio file

36 messages · Page 1 of 1 (latest)

wise elbow
#

Hello, I started a few days ago with discordjs, I have now tried to play an audio that I have locally, a lot of information is from discord 12 or 13 and in 14 I can't find much help, I don't know why the bot joins To the voice channel, the playing audio log pops up but it doesn't play any audio, I gave it all the permissions I would swear to the voice and when I put logs to catch errors I don't get that it is going at all wrong in reading

This is my replit repo
https://replit.com/@FranyxD/Zetydiscordbot?s=app

FranyxD

Run Node.js code live in your browser. Write and run code in 50+ languages online with Replit, a powerful IDE, compiler, & interpreter.

vague jewelBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
wise elbow
#

My discord is 14.15.2 and my discord voice is 0.17
Using the lts of node

lofty flower
#

Do you have ffmpeg?

wise elbow
#

Yes, I have it in my package.json dependencies

#

I have mp3 and ogg filed just in case

lofty flower
#

Show your code where you try to play the resource then. Is the file path correct? Remember that fs uses paths relative to where node is run from, not the directory your js file is in

wise elbow
#

It's the /commands/utility/play.js

lofty flower
#

I won‘t go through your files. If you want help show the code

wise elbow
#

Okay

#

module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription(
"Command to make the bot join a voice channel and play an mp3",
),
async execute(interaction) {
if (!interaction.inGuild()) {
// Check if the command was used in a guild
interaction.reply("This command can only be used in a server.");
return;
}

const { member } = interaction; // Get the member who ran the command
const channel = member.voice.channel; // Get the voice channel the member is in

if (!channel) {
  // Check if the member is in a voice channel
  interaction.reply("You need to be in a voice channel to play audio!");
  return;
}

if (!channel.permissionsFor(interaction.guild.members.me).has("STREAM")) {
  interaction.reply("I don't have permission to stream audio in this voice channel.");
  return;
}

// Join the voice channel
const connection = joinVoiceChannel({
  // Create a connection to the voice channel
  channelId: channel.id, // Use the ID of the voice channel
  guildId: channel.guild.id, // Use the ID of the guild
  adapterCreator: channel.guild.voiceAdapterCreator,
  selfDeaf: false,
});

// Play audio
const player = createAudioPlayer();
const resource = createAudioResource('./sample.ogg');
player.play(resource);

// Play "track.mp3" across two voice connections
connection.subscribe(player);

// Check if the bot is playing audio
  player.on(AudioPlayerStatus.Playing, () => {
  console.log("Bot is playing audio.");
});

// Check if the bot is reading the mp3 file
  player.on(AudioPlayerStatus.Buffering, () => {
  console.log("Bot is reading the mp3 file.");
});

await interaction.reply("Playing mp3");

},
};

#

Using discord guide, I don't know what I'm missing

lofty flower
#

That’s not v14 syntax. Can you double check your discord.js version? Because that should always reply with not having permissions

wise elbow
#

It's 14.15.2

#

I have never gotten an error that I don't have permissions.

lofty flower
#

Ah, lemme guess, your bot is admin?

wise elbow
#

Yes

lofty flower
#

Bots can’t stream (video), the permission you want to check is Connect. And all permissions etc. are PascalCase in v14, not SCREMAING_SNAKE_CASE

#

But for your actual issue I assume the file paths is simply wrong. Use absolute paths (for example using path.resolve) not relative

wise elbow
#

I ll try that

#

The other message you send me I don't understand at all

lofty flower
#

Not a word of it?

wise elbow
#

Nope 😅

#

// Play audio
const player = createAudioPlayer();
const resource = createAudioResource(path.resolve(__dirname, 'sample.ogg'));
player.play(resource);

// Play "track.mp3" across two voice connections
connection.subscribe(player);
#

This?

lofty flower
# wise elbow Nope 😅

Kinda doubt that. If you don’t know the word „bot“ or „can‘t“ or „the“ etc. you really should ask somewhere else

wise elbow
#

Bot, can't and the I know

#

It's just I don't know what you mean, I need to change the bot permission?

lofty flower
#

You need to change the permission you check for there

#

There is no permission named STREAM in v14. There is one named Stream, but that’s irrelevant for what you try to do

wise elbow
#

So if it's irrelevant, why not works? I change to absolute and it's the same
What type of permission need to mark at the bot

fringe vectorBOT
#

guide Getting Started: Introduction - Debugging Dependencies
read more

wise elbow
#

Do you have an example files of how to do this things? In guide don't finde for discord voice

cerulean perch
#

I'd start with logging the states