cannot hear my bot

Hi. I found my old "play-mp3" command. However, when I tried it out it didn't play any audio. The code doesn't throw any errors. Now I have no idea whether it's me or the bot.
const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const { ChannelType, EmbedBuilder } = require('discord.js');
const path = require('path');
module.exports = {
data: new SlashCommandBuilder()
.setName('play-mp3')
.setDescription('Spielt eine MP3-Datei ab.')
.addStringOption(option =>
option.setName('song')
.setDescription('-')
.setRequired(true)
.addChoices(
{
name: 'Song 1', value: `Third_Party_Normal`
},
))
.addChannelOption((option) => option.setName('channel').setDescription('Voicechannel').setRequired(true).addChannelTypes(ChannelType.GuildVoice)),
async execute(interaction) {
const track = await interaction.options.getString('song');
try {
const vchannel = interaction.options.getChannel('channel');
global.connection = joinVoiceChannel({
channelId: vchannel.id,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: true,
selfMute: false
});
global.connection.on('debug', (m) => {
console.log('Voice Debug:', m);
});
} catch (error) {
console.error(error);
await interaction.reply('Es gab einen Fehler beim Abspielen der Musik.');
}
try {
const player = createAudioPlayer();
const resource = createAudioResource(`./src/media/${track}.mp3`);
player.play(resource);
global.connection.subscribe(player);
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle("Playing Audio!")
.setDescription(`Now playing ---| ${track} |---`)
.setFooter({ text: `Nachricht von ${interaction.user.tag} am ${new Date().toLocaleString()}` })
]
})
} catch (error) {
console.error(error);
await interaction.reply('Es gab einen Fehler beim Abspielen der Musik.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const { ChannelType, EmbedBuilder } = require('discord.js');
const path = require('path');
module.exports = {
data: new SlashCommandBuilder()
.setName('play-mp3')
.setDescription('Spielt eine MP3-Datei ab.')
.addStringOption(option =>
option.setName('song')
.setDescription('-')
.setRequired(true)
.addChoices(
{
name: 'Song 1', value: `Third_Party_Normal`
},
))
.addChannelOption((option) => option.setName('channel').setDescription('Voicechannel').setRequired(true).addChannelTypes(ChannelType.GuildVoice)),
async execute(interaction) {
const track = await interaction.options.getString('song');
try {
const vchannel = interaction.options.getChannel('channel');
global.connection = joinVoiceChannel({
channelId: vchannel.id,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: true,
selfMute: false
});
global.connection.on('debug', (m) => {
console.log('Voice Debug:', m);
});
} catch (error) {
console.error(error);
await interaction.reply('Es gab einen Fehler beim Abspielen der Musik.');
}
try {
const player = createAudioPlayer();
const resource = createAudioResource(`./src/media/${track}.mp3`);
player.play(resource);
global.connection.subscribe(player);
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle("Playing Audio!")
.setDescription(`Now playing ---| ${track} |---`)
.setFooter({ text: `Nachricht von ${interaction.user.tag} am ${new Date().toLocaleString()}` })
]
})
} catch (error) {
console.error(error);
await interaction.reply('Es gab einen Fehler beim Abspielen der Musik.');
}
},
};
3 Replies
d.js toolkit
d.js toolkit13mo 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
ShompiFlen13mo ago
what is your discord.js version and which intents are you currently using
Serial Designation N
i fixed it. i wass missing the GuildVoiceStates intent :,) But another question: How can I detect the end of the audio to restart it automatically? can i fetch the active player and pause it when clicking a button?
Want results from more Discord servers?
Add your server