Guest User

Untitled

a guest
May 26th, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { SlashCommandBuilder } = require('@discordjs/builders');
  2. const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus  } = require('@discordjs/voice');
  3.  
  4. const path = require('path');
  5.  
  6. module.exports = {
  7.     data: new SlashCommandBuilder()
  8.         .setName('play')
  9.         .setDescription('Play songs in your voice channel')
  10.         .addStringOption(option =>
  11.             option.setName('song')
  12.                 .setDescription('Input a song to play')
  13.                 .setRequired(true)),
  14.     async execute(client, interaction) {
  15.         const guild = client.guilds.cache.get(interaction.guildId)
  16.         const member = guild.members.cache.get(interaction.member.user.id);
  17.         const voiceChannel = member.voice.channel;
  18.         const connection = joinVoiceChannel({
  19.             channelId: interaction.channelId,
  20.             guildId: interaction.guildId,
  21.             adapterCreator: interaction.guild.voiceAdapterCreator,
  22.         });
  23.         const player = createAudioPlayer();
  24.         const resource = createAudioResource(path.join(__dirname, 'test.mp3'));
  25.         player.play(resource);
  26.         connection.subscribe(player);
  27.         player.on(AudioPlayerStatus.Playing, (oldState, newState) => {
  28.             console.log('Audio player is in the Playing state!');
  29.         });
  30.         await interaction.reply('Hello World!');
  31.     },
  32. };
Advertisement
Add Comment
Please, Sign In to add comment