First Version

This commit is contained in:
CICD - Pipeline 2023-04-10 14:52:23 +02:00
parent 02c8262d4c
commit 23814fbb24
12 changed files with 1603 additions and 10 deletions

61
.gitignore vendored Normal file
View File

@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# next.js build output
.next

View File

@ -1,3 +1,3 @@
# default
# Subsonics
Modèle de projet par défaut.
Bot Discord Youtube Reader

View File

1211
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,13 @@
{
"name": "subsonics-bot",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "nodemon main.js"
},
"name": "subsonics-discord",
"author": "Raphix",
"license": "ISC"
"version": "1.0.0",
"dependencies": {
"discord.js": "^14.9.0",
"erela.js": "^2.4.0",
"nodemon": "^2.0.22"
},
"scripts": {
"start": "nodemon src/main.js"
}
}

37
src/commands/leave.js Normal file
View 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
View 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
View 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
View 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
View 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
View File

@ -0,0 +1,5 @@
{
"token":"MTA5NDcyNzc4OTY4MjM4MDkyMg.G4LcLR.qMZsDn_iR0rrVyie7yXxfmltn3Z_CaQIXMxUiU",
"clientID":"1094727789682380922",
"guildID":"137291455336022018"
}

128
src/main.js Normal file
View 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)