Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { SlashCommandBuilder } = require('@discordjs/builders');
- const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');
- const path = require('path');
- module.exports = {
- data: new SlashCommandBuilder()
- .setName('play')
- .setDescription('Play songs in your voice channel')
- .addStringOption(option =>
- option.setName('song')
- .setDescription('Input a song to play')
- .setRequired(true)),
- async execute(client, interaction) {
- const guild = client.guilds.cache.get(interaction.guildId)
- const member = guild.members.cache.get(interaction.member.user.id);
- const voiceChannel = member.voice.channel;
- const connection = joinVoiceChannel({
- channelId: interaction.channelId,
- guildId: interaction.guildId,
- adapterCreator: interaction.guild.voiceAdapterCreator,
- });
- const player = createAudioPlayer();
- const resource = createAudioResource(path.join(__dirname, 'test.mp3'));
- player.play(resource);
- connection.subscribe(player);
- player.on(AudioPlayerStatus.Playing, (oldState, newState) => {
- console.log('Audio player is in the Playing state!');
- });
- await interaction.reply('Hello World!');
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment