prepare client in separate file

This commit is contained in:
Mylloon 2022-07-03 17:48:33 +02:00
parent 574583389f
commit 7eb61b0700
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 23 additions and 5 deletions

View file

@ -1,4 +1,4 @@
const { Client, Intents } = require('discord.js'); import loadClient from './utils/client.js';
const run = async () => { const run = async () => {
console.log('Starting Botanique...'); console.log('Starting Botanique...');
@ -10,12 +10,11 @@ const run = async () => {
} }
// Client Discord.JS // Client Discord.JS
const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); const client = await loadClient().catch(() => {
client.config = { token_discord: process.env.TOKEN_DISCORD }; throw 'Client ❌';
});
if (client) { if (client) {
console.log('Client ✅'); console.log('Client ✅');
} else {
throw 'Client ❌';
} }
await client.login(client.config.token_discord); await client.login(client.config.token_discord);

19
src/utils/client.js Normal file
View file

@ -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;
};