const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const { ChannelType } = require('discord.js');
const path = require('path');
module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Spielt eine MP3-Datei ab.')
.addChannelOption((option) => option.setName('channel').setDescription('Voicechannel').setRequired(true).addChannelTypes(ChannelType.GuildVoice)),
async execute(interaction) {
try {
const vchannel = interaction.options.getChannel('channel');
const connection = joinVoiceChannel({
channelId: vchannel.id,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator,
});
const player = createAudioPlayer();
const resource = createAudioResource(path.join(__dirname, 'Final.mp3'));
await player.play(resource);
connection.subscribe(player);
await interaction.reply('Musik wird abgespielt.');
} catch (error) {
console.error(error);
await interaction.reply('Es gab einen Fehler beim Abspielen der Musik.');
}
},
};