33 lines
1019 B
JavaScript
33 lines
1019 B
JavaScript
const { getMusicStream } = require("./../utils/getMusicStream");
|
|
const musicQueue = require("../musicQueue");
|
|
const { musicPlayer } = require("../utils/musicPlayer");
|
|
const { joinVoiceChannel } = require("@discordjs/voice");
|
|
|
|
async function playCommand(interaction) {
|
|
await interaction.deferReply();
|
|
|
|
const query = interaction.options.getString("input");
|
|
const voiceChannel = interaction.member.voice.channel;
|
|
|
|
if (!voiceChannel) {
|
|
return interaction.followUp(
|
|
"You must be in a voice channel to use this command."
|
|
);
|
|
}
|
|
const song = await getMusicStream(query);
|
|
|
|
musicQueue.addToQueue(interaction.guild.id, song);
|
|
|
|
const connection = joinVoiceChannel({
|
|
channelId: voiceChannel.id,
|
|
guildId: interaction.guild.id,
|
|
adapterCreator: interaction.guild.voiceAdapterCreator,
|
|
selfDeaf: false,
|
|
selfMute: false,
|
|
});
|
|
|
|
musicPlayer(interaction.guild.id, connection, interaction);
|
|
}
|
|
|
|
module.exports.playCommand = playCommand;
|