diff --git a/src/index.js b/src/index.js index d59bd40..3324e65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -const { Client, Intents } = require('discord.js'); +import loadClient from './utils/client.js'; const run = async () => { console.log('Starting Botanique...'); @@ -10,12 +10,11 @@ const run = async () => { } // Client Discord.JS - const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); - client.config = { token_discord: process.env.TOKEN_DISCORD }; + const client = await loadClient().catch(() => { + throw 'Client ❌'; + }); if (client) { console.log('Client ✅'); - } else { - throw 'Client ❌'; } await client.login(client.config.token_discord); diff --git a/src/utils/client.js b/src/utils/client.js new file mode 100644 index 0000000..ba942f0 --- /dev/null +++ b/src/utils/client.js @@ -0,0 +1,19 @@ +import { Client, Intents } from 'discord.js'; +import { readFileSync } from 'fs'; +const { version } = JSON.parse(readFileSync('./package.json')); + +// Création du client et de ses propriétés +export default async () => { + const client = new Client({ + intents: [ + Intents.FLAGS.GUILDS, + ], + }); + + client.config = { + version: version, + token_discord: process.env.TOKEN_DISCORD, + }; + + return client; +};