Compare commits
No commits in common. "3a7546e0dfa2c0e817cb6dc6d4d1b8280549711d" and "7eb61b07007dd835e6bba1fefe6a9f785236bc6f" have entirely different histories.
3a7546e0df
...
7eb61b0700
4 changed files with 8 additions and 57 deletions
|
@ -1,5 +0,0 @@
|
||||||
export const once = true;
|
|
||||||
|
|
||||||
export default async () => {
|
|
||||||
console.log('Connecté à Discord !');
|
|
||||||
};
|
|
|
@ -1,36 +0,0 @@
|
||||||
import { readdir } from 'fs/promises';
|
|
||||||
|
|
||||||
export default async client => {
|
|
||||||
const events_categories = (await readdir('./src/events'))
|
|
||||||
.filter(element => !element.endsWith('.js'));
|
|
||||||
|
|
||||||
events_categories.forEach(async event_category => {
|
|
||||||
// Retrieve events
|
|
||||||
const events = await readdir(`./src/events/${event_category}`);
|
|
||||||
|
|
||||||
// Load them into the client
|
|
||||||
Promise.all(
|
|
||||||
events.map(async event_file => {
|
|
||||||
const { once, default: execute } = await import(
|
|
||||||
`../events/${event_category}/${event_file}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove .js
|
|
||||||
let event_type = event_file.split('.');
|
|
||||||
if (event_type.pop() !== 'js') {
|
|
||||||
throw `Unknown file in ${event_category}: ${event_file}`;
|
|
||||||
}
|
|
||||||
event_type = event_type.join('.');
|
|
||||||
|
|
||||||
if (once) {
|
|
||||||
return client.once(event_type, (...args) => {
|
|
||||||
execute(...args, client);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return client.on(event_type, (...args) => {
|
|
||||||
execute(...args, client);
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
17
src/index.js
17
src/index.js
|
@ -1,30 +1,23 @@
|
||||||
import loadClient from './utils/client.js';
|
import loadClient from './utils/client.js';
|
||||||
import loadEvents from './events/loader.js';
|
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
console.log('Starting Botanique...');
|
console.log('Starting Botanique...');
|
||||||
|
|
||||||
// Load .env if not in prod
|
// Load .env if not in prod
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
(await import('dotenv')).config({ path: './config/.env' });
|
const dotenv = await import('dotenv');
|
||||||
|
dotenv.config({ path: './config/.env' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client Discord.JS
|
// Client Discord.JS
|
||||||
const client = await loadClient()
|
const client = await loadClient().catch(() => {
|
||||||
.catch(() => {
|
|
||||||
throw 'Client ❌';
|
throw 'Client ❌';
|
||||||
});
|
});
|
||||||
|
if (client) {
|
||||||
console.log('Client ✅');
|
console.log('Client ✅');
|
||||||
|
}
|
||||||
await loadEvents(client)
|
|
||||||
.then(() => console.log('Events ✅'))
|
|
||||||
.catch(() => {
|
|
||||||
throw 'Events ❌';
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.login(client.config.token_discord);
|
await client.login(client.config.token_discord);
|
||||||
|
|
||||||
console.log(`Botanique "${client.user.username}" ${client.config.version} started!`);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
run().catch(error => console.error(error));
|
run().catch(error => console.error(error));
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { Client, Intents } from 'discord.js';
|
import { Client, Intents } from 'discord.js';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
|
|
||||||
const { version } = JSON.parse(readFileSync('./package.json'));
|
const { version } = JSON.parse(readFileSync('./package.json'));
|
||||||
|
|
||||||
// Création du client et de ses propriétés
|
// Création du client et de ses propriétés
|
||||||
|
|
Loading…
Reference in a new issue