bot/src/commands/play.js

87 lines
2.8 KiB
JavaScript
Raw Normal View History

2023-04-10 12:52:23 +00:00
const { EmbedBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder, Embed } = require("discord.js");
module.exports = {
data:new SlashCommandBuilder()
.setName("play")
.setDescription("Lire une musique depuis youtube")
2023-04-10 15:41:59 +00:00
.addStringOption(option => option.setName("nom_ou_lien").setDescription("Le nom de la musique recherchée !").setRequired(true)),
2023-04-10 12:52:23 +00:00
async execute(client, interaction) {
2023-04-10 15:41:59 +00:00
const song_name = interaction.options.getString("nom_ou_lien")
2023-04-10 12:52:23 +00:00
if(!interaction.member.voice.channel) return interaction.reply({content:"Vous devez rejoindre un salon vocal !", ephemeral: true})
let player = client.manager.players.get(interaction.guild.id)
2023-04-10 15:41:59 +00:00
if(!player) {
player = client.manager.create({
2023-04-10 12:52:23 +00:00
guild: interaction.guild.id,
voiceChannel: interaction.member.voice.channel.id,
textChannel: interaction.channel.id,
2023-04-10 15:41:59 +00:00
});
player.connect();
}
2023-04-10 12:52:23 +00:00
const songs = await client.manager.search(song_name)
2023-04-10 15:41:59 +00:00
if(!player.playing) {
client.manager.players.get(interaction.guild.id).queue.add(songs.tracks[0])
player.play()
const embed = await new EmbedBuilder()
.setColor(0x15e6ed)
.setTitle('**Lecture de **' + songs.tracks[0].title)
.setDescription('**Demandé par **' + interaction.member.user.username)
.addFields({name: "Auteur", value: songs.tracks[0].author},
{name: "URL", value:songs.tracks[0].uri})
.setThumbnail(songs.tracks[0].thumbnail)
.setTimestamp();
try {
interaction.reply({embeds: [embed]})
} catch(error) {
interaction.reply({embeds: [embed]})
}
} else {
const embed = await new EmbedBuilder()
.setColor(0x15e6ed)
.setTitle('**Ajout dans la liste de lecture **' + songs.tracks[0].title)
.setDescription('**Demandé par **' + interaction.member.user.username)
.addFields({name: "Auteur", value: songs.tracks[0].author},
{name: "URL", value:songs.tracks[0].uri})
.setThumbnail(songs.tracks[0].thumbnail)
.setTimestamp();
client.manager.players.get(interaction.guild.id).queue.add(songs.tracks[0])
console.log("------------------------PLAY.JS---------------------")
console.log(player.queue)
console.log("--------------------------------------------")
try {
2023-04-10 12:52:23 +00:00
2023-04-10 15:41:59 +00:00
interaction.reply({embeds: [embed]})
} catch(error) {
2023-04-10 12:52:23 +00:00
2023-04-10 15:41:59 +00:00
interaction.reply({embeds: [embed]})
}
2023-04-10 12:52:23 +00:00
2023-04-10 15:41:59 +00:00
}
2023-04-10 12:52:23 +00:00
}
}