First Version
This commit is contained in:
37
src/commands/leave.js
Normal file
37
src/commands/leave.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
|
||||
data:new SlashCommandBuilder()
|
||||
.setName("leave")
|
||||
.setDescription("Faire partir le meilleur groupe du monde !"),
|
||||
|
||||
async execute(client, interaction) {
|
||||
|
||||
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)
|
||||
|
||||
if(player) {
|
||||
|
||||
player.disconnect()
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xff0000)
|
||||
.setTitle('C\'est tout pour nous !')
|
||||
.setDescription("**Le meilleur groupe du monde est parti ... !**")
|
||||
.setTimestamp();
|
||||
|
||||
|
||||
interaction.reply({embeds: [embed]})
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
interaction.reply("**Aucune musique n'est actuellement joué !**")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
40
src/commands/pause.js
Normal file
40
src/commands/pause.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("pause")
|
||||
.setDescription("Met en pause la musique joué !"),
|
||||
|
||||
async execute(client, interaction) {
|
||||
|
||||
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)
|
||||
|
||||
if(player) {
|
||||
|
||||
if(player.playing) {
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0x03ff2d)
|
||||
.setTitle('Pause !')
|
||||
.setDescription("**Ok, une entracte est demandé par " + interaction.member.user.username + "**")
|
||||
.setTimestamp();
|
||||
|
||||
|
||||
interaction.reply({embeds: [embed]})
|
||||
|
||||
player.pause(true)
|
||||
} else {
|
||||
interaction.reply("**Aucune musique n'est actuellement joué !**")
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
interaction.reply("**Aucune musique n'est actuellement joué !**")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
22
src/commands/ping.js
Normal file
22
src/commands/ping.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
.setDescription("Affiche le ping du bot !"),
|
||||
|
||||
async execute(client, interaction) {
|
||||
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xb0f542)
|
||||
.setTitle('Résultat du ping')
|
||||
.setDescription("**Ping :** " + client.ws.ping + " ms")
|
||||
.setTimestamp();
|
||||
|
||||
|
||||
interaction.reply({embeds: [embed]})
|
||||
|
||||
}
|
||||
}
|
47
src/commands/play.js
Normal file
47
src/commands/play.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const { EmbedBuilder } = require("@discordjs/builders");
|
||||
const { SlashCommandBuilder, Embed } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
|
||||
data:new SlashCommandBuilder()
|
||||
.setName("play")
|
||||
.setDescription("Lire une musique depuis youtube")
|
||||
.addStringOption(option => option.setName("nom").setDescription("Le nom de la musique recherché !").setRequired(true)),
|
||||
|
||||
async execute(client, interaction) {
|
||||
|
||||
const song_name = interaction.options.getString("nom")
|
||||
|
||||
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)
|
||||
|
||||
if(!player) player = client.manager.create({
|
||||
guild: interaction.guild.id,
|
||||
voiceChannel: interaction.member.voice.channel.id,
|
||||
textChannel: interaction.channel.id,
|
||||
});
|
||||
|
||||
const songs = await client.manager.search(song_name)
|
||||
|
||||
player.connect();
|
||||
|
||||
player.queue.add(songs.tracks[0])
|
||||
|
||||
if(!player.playing) player.play()
|
||||
|
||||
console.log(songs.tracks[0])
|
||||
|
||||
const embed = 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();
|
||||
|
||||
|
||||
interaction.reply({embeds: [embed]})
|
||||
}
|
||||
}
|
40
src/commands/resume.js
Normal file
40
src/commands/resume.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("resume")
|
||||
.setDescription("Met en pause la musique joué !"),
|
||||
|
||||
async execute(client, interaction) {
|
||||
|
||||
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)
|
||||
|
||||
if(player) {
|
||||
|
||||
if(!player.playing) {
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0x03ff2d)
|
||||
.setTitle('C\'est reparti !')
|
||||
.setDescription("**Ok, Fin de l'entracte, c'est reparti et c'est demandé par " + interaction.member.user.username + "**")
|
||||
.setTimestamp();
|
||||
|
||||
|
||||
interaction.reply({embeds: [embed]})
|
||||
|
||||
player.pause(false)
|
||||
} else {
|
||||
interaction.reply("**Aucune musique n'est actuellement joué !**")
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
interaction.reply("**Aucune musique n'est actuellement joué !**")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
5
src/config.json
Normal file
5
src/config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"token":"MTA5NDcyNzc4OTY4MjM4MDkyMg.G4LcLR.qMZsDn_iR0rrVyie7yXxfmltn3Z_CaQIXMxUiU",
|
||||
"clientID":"1094727789682380922",
|
||||
"guildID":"137291455336022018"
|
||||
}
|
128
src/main.js
Normal file
128
src/main.js
Normal file
@@ -0,0 +1,128 @@
|
||||
const { Client, GatewayIntentBits, Collection } = require("discord.js")
|
||||
const { REST, Routes } = require("discord.js")
|
||||
const fs = require("node:fs")
|
||||
const config = require("./config.json")
|
||||
const path = require("path")
|
||||
const { Manager } = require("erela.js")
|
||||
|
||||
const client = new Client({
|
||||
intents:[GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMembers]
|
||||
})
|
||||
|
||||
client.commands = new Collection()
|
||||
|
||||
const commands = [];
|
||||
// Grab all the command files from the commands directory you created earlier
|
||||
const commandsPath = path.join(__dirname , 'commands');
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`./commands/${file}`);
|
||||
client.commands.set(command.data.name, command)
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
|
||||
// Construct and prepare an instance of the REST module
|
||||
const rest = new REST().setToken(config.token);
|
||||
|
||||
// and deploy your commands!
|
||||
(async () => {
|
||||
try {
|
||||
|
||||
|
||||
|
||||
|
||||
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||
|
||||
// The put method is used to fully refresh all commands in the guild with the current set
|
||||
const data = await rest.put(
|
||||
Routes.applicationGuildCommands(config.clientID, config.guildID),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
|
||||
} catch (error) {
|
||||
// And of course, make sure you catch and log any errors!
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
|
||||
// Command Slash
|
||||
|
||||
|
||||
// Client Event
|
||||
|
||||
client.once("ready", () => {
|
||||
|
||||
console.log("Le meilleur groupe de musique est prêt !")
|
||||
client.manager.init(client.user.id);
|
||||
|
||||
const commandManager = client.application.commands;
|
||||
|
||||
if (!commandManager) {
|
||||
console.log('Command manager not available.');
|
||||
|
||||
} else {
|
||||
|
||||
commandManager.set([]);
|
||||
}
|
||||
})
|
||||
|
||||
client.on("interactionCreate", (interaction) => {
|
||||
|
||||
if(!interaction.isCommand()) return;
|
||||
|
||||
const command = client.commands.get(interaction.commandName)
|
||||
|
||||
try {
|
||||
command.execute(client, interaction)
|
||||
} catch(error) {
|
||||
|
||||
interaction.reply({content:"Erreur lors de l'éxécution de la commande !", ephemeral: true})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const nodes = [
|
||||
{
|
||||
host: "lavalink.lexnet.cc",
|
||||
password: "lexn3tl@val!nk",
|
||||
port: 443,
|
||||
secure: true
|
||||
}
|
||||
];
|
||||
|
||||
client.manager = new Manager({
|
||||
// The nodes to connect to, optional if using default lavalink options
|
||||
nodes,
|
||||
// Method to send voice data to Discord
|
||||
send: (id, payload) => {
|
||||
const guild = client.guilds.cache.get(id);
|
||||
// NOTE: FOR ERIS YOU NEED JSON.stringify() THE PAYLOAD
|
||||
if (guild) guild.shard.send(payload);
|
||||
}
|
||||
});
|
||||
|
||||
// Emitted whenever a node connects
|
||||
client.manager.on("nodeConnect", node => {
|
||||
console.log(`Node "${node.options.identifier}" connected.`)
|
||||
})
|
||||
|
||||
// Emitted whenever a node encountered an error
|
||||
client.manager.on("nodeError", (node, error) => {
|
||||
console.log(`Node "${node.options.identifier}" encountered an error: ${error.message}.`)
|
||||
})
|
||||
|
||||
|
||||
// THIS IS REQUIRED. Send raw events to Erela.js
|
||||
client.on("raw", d => client.manager.updateVoiceState(d));
|
||||
|
||||
|
||||
// Client Manager
|
||||
|
||||
client.login(config.token)
|
Reference in New Issue
Block a user