init base

This commit is contained in:
Tutur33
2024-02-13 23:28:33 +01:00
parent 3e79697d37
commit ab1520b104
6 changed files with 98 additions and 77 deletions
+9
View File
@@ -0,0 +1,9 @@
const { MessageEmbed } = require('discord.js');
module.exports = {
name: 'ping',
description: 'Command to check the latency of the bot.',
async execute(message, args, client) {
message.channel.send('test');
},
};
+2 -5
View File
@@ -1,14 +1,11 @@
const { Events, InteractionType } = require("discord.js") const { Events, InteractionType } = require("discord.js");
module.exports = { module.exports = {
name: Events.InteractionCreate, name: Events.InteractionCreate,
async run(client, interaction) { async run(client, interaction) {
if (interaction.type === InteractionType.ApplicationCommand) { if (interaction.type === InteractionType.ApplicationCommand) {
const command = client.commands.get(interaction.commandName); const command = client.commands.get(interaction.commandName);
await command.execute(interaction, client); await command.execute(interaction, client);
};
} }
},
}; };
+21 -6
View File
@@ -1,15 +1,30 @@
const { Events, ActivityType } = require("discord.js") const { Events, ActivityType } = require("discord.js");
module.exports = {
module.exports = {
name: Events.ClientReady, name: Events.ClientReady,
async run(client) { async run(client) {
if (client.commands && Array.isArray(client.commands)) { if (client.commands && Array.isArray(client.commands)) {
client.application.commands.set(client.commands.map(command => command.data)); client.application.commands.set(
client.commands.map((command) => command.data)
);
} else { } else {
console.error('Les commandes du client sont manquantes ou mal formatées'); console.error("Les commandes du client sont manquantes ou mal formatées\n");
} }
console.log(`${client.user.username} est en ligne`); console.log(`
[${new Date().toLocaleString()}] Logged in as ${client.user.tag} with:
- ${client.guilds.cache.size} guilds
- ${client.channels.cache.size} channels
- ${client.users.cache.size} users
`);
client.user.setActivity({
name: "&help",
type: ActivityType.Streaming, //Playing, Streaming, Listening, Watching, Custom, Competing
url: "https://www.twitch.tv/tuturp33"
});
const activityTypes = ['Playing', 'Streaming', 'Listening', 'Watching', 'Custom', 'Competing'];
let activityType = activityTypes[client.user.presence.activities[0].type] || 'Unknown';
console.log(`[${new Date().toLocaleString()}] Bot activity set to ${activityType}: ${client.user.presence.activities[0].name}\n`);
}, },
}; };
+13 -11
View File
@@ -1,13 +1,14 @@
const fs = require('fs'); const fs = require("fs");
const path = require('path'); const path = require("path");
module.exports = (client) => { module.exports = (client) => {
const loadCommands = (dir) => {
let count = 0; let count = 0;
fs.readdirSync(path.join(__dirname, dir)).forEach(file => { const loadCommands = (dir) => {
fs.readdirSync(path.join(__dirname, dir)).forEach((file) => {
const filePath = path.join(__dirname, dir, file); const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) { if (fs.statSync(filePath).isDirectory()) {
count += loadCommands(path.join(dir, file)); count += loadCommands(path.join(dir, file));
} else if (file.endsWith('.js')) { } else if (file.endsWith(".js")) {
try { try {
// Delete the cache for this command file // Delete the cache for this command file
delete require.cache[require.resolve(filePath)]; delete require.cache[require.resolve(filePath)];
@@ -15,14 +16,15 @@ module.exports = (client) => {
client.commands.set(command.name, command); client.commands.set(command.name, command);
count++; count++;
} catch (error) { } catch (error) {
console.error(`Failed to load file: ${filePath}`); // Log any errors console.error(`Failed to load file: ${filePath}\n`, error, '\n');
console.error(error); //console.error(`Failed to load file: ${filePath}`); // Log any errors
//console.error(error);
} }
} }
}); });
return count; return count;
} };
const totalCommands = loadCommands('../commands'); const totalCommands = loadCommands("../commands");
console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot`); console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot\n`);
} };
+10 -9
View File
@@ -1,15 +1,15 @@
const fs = require('fs'); const fs = require("fs");
const path = require('path'); const path = require("path");
module.exports = (client) => { module.exports = (client) => {
let count = 0; let count = 0;
const loadEvents = (dir) => { const loadEvents = (dir) => {
fs.readdirSync(path.join(__dirname, dir)).forEach(file => { fs.readdirSync(path.join(__dirname, dir)).forEach((file) => {
const filePath = path.join(__dirname, dir, file); const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) { if (fs.statSync(filePath).isDirectory()) {
loadEvents(path.join(dir, file)); loadEvents(path.join(dir, file));
} else if (file.endsWith('.js')) { } else if (file.endsWith(".js")) {
// Delete the cache for this command file
delete require.cache[require.resolve(filePath)]; delete require.cache[require.resolve(filePath)];
const event = require(filePath); const event = require(filePath);
client.on(event.name, (...args) => event.run(...args, client)); client.on(event.name, (...args) => event.run(...args, client));
@@ -17,7 +17,8 @@ module.exports = (client) => {
count++; count++;
} }
}); });
} };
loadEvents('../events');
console.log(`Event => ${count} chargé sur le bot`) loadEvents("../events");
} console.log(`Event => ${count} chargé sur le bot\n`);
};
+4 -7
View File
@@ -1,15 +1,12 @@
require('dotenv').config(); require('dotenv').config();
const { Client, IntentsBitField, Collection } = require("discord.js"); const { Client, IntentsBitField, Collection } = require("discord.js");
const loadCommands = require("./loaders/loadCommands") const loadCommands = require("./loaders/loadCommands");
const loadEvents = require("./loaders/loadEvents"); const loadEvents = require("./loaders/loadEvents");
const client = new Client({intents: new IntentsBitField(3276799)}); const client = new Client({intents: new IntentsBitField(3276799)});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
(async () => { (async () => {
await loadCommands(client); loadCommands(client);
await loadEvents(client); loadEvents(client);
await client.login(process.env.TOKEN); await client.login(process.env.TOKEN);
})(); })();
client.login(process.env.TOKEN);