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');
},
};
+8 -11
View File
@@ -1,14 +1,11 @@
const { Events, InteractionType } = require("discord.js")
const { Events, InteractionType } = require("discord.js");
module.exports = {
name :Events.InteractionCreate,
async run(client, interaction) {
if(interaction.type === InteractionType.ApplicationCommand) {
const command = client.commands.get(interaction.commandName);
await command.execute(interaction, client);
};
name: Events.InteractionCreate,
async run(client, interaction) {
if (interaction.type === InteractionType.ApplicationCommand) {
const command = client.commands.get(interaction.commandName);
await command.execute(interaction, client);
}
};
},
};
+26 -11
View File
@@ -1,15 +1,30 @@
const { Events, ActivityType } = require("discord.js")
const { Events, ActivityType } = require("discord.js");
module.exports = {
name: Events.ClientReady,
async run(client) {
if (client.commands && Array.isArray(client.commands)) {
client.application.commands.set(
client.commands.map((command) => command.data)
);
} else {
console.error("Les commandes du client sont manquantes ou mal formatées\n");
}
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
`);
name : Events.ClientReady,
async run(client) {
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`);
if (client.commands && Array.isArray(client.commands)) {
client.application.commands.set(client.commands.map(command => command.data));
} else {
console.error('Les commandes du client sont manquantes ou mal formatées');
}
console.log(`${client.user.username} est en ligne`);
},
},
};
+29 -27
View File
@@ -1,28 +1,30 @@
const fs = require('fs');
const path = require('path');
module.exports = (client) => {
const loadCommands = (dir) => {
let count = 0;
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
count += loadCommands(path.join(dir, file));
} else if (file.endsWith('.js')) {
try {
// Delete the cache for this command file
delete require.cache[require.resolve(filePath)];
const command = require(filePath);
client.commands.set(command.name, command);
count++;
} catch (error) {
console.error(`Failed to load file: ${filePath}`); // Log any errors
console.error(error);
}
}
});
return count;
}
const fs = require("fs");
const path = require("path");
const totalCommands = loadCommands('../commands');
console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot`);
}
module.exports = (client) => {
let count = 0;
const loadCommands = (dir) => {
fs.readdirSync(path.join(__dirname, dir)).forEach((file) => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
count += loadCommands(path.join(dir, file));
} else if (file.endsWith(".js")) {
try {
// Delete the cache for this command file
delete require.cache[require.resolve(filePath)];
const command = require(filePath);
client.commands.set(command.name, command);
count++;
} catch (error) {
console.error(`Failed to load file: ${filePath}\n`, error, '\n');
//console.error(`Failed to load file: ${filePath}`); // Log any errors
//console.error(error);
}
}
});
return count;
};
const totalCommands = loadCommands("../commands");
console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot\n`);
};
+21 -20
View File
@@ -1,23 +1,24 @@
const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");
module.exports = (client) => {
let count = 0;
const loadEvents = (dir) => {
fs.readdirSync(path.join(__dirname, dir)).forEach((file) => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
loadEvents(path.join(dir, file));
} else if (file.endsWith(".js")) {
// Delete the cache for this command file
delete require.cache[require.resolve(filePath)];
const event = require(filePath);
client.on(event.name, (...args) => event.run(...args, client));
console.log(`Event ${event.name} loaded`);
count++;
}
});
};
let count = 0;
const loadEvents = (dir) => {
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
loadEvents(path.join(dir, file));
} else if (file.endsWith('.js')) {
delete require.cache[require.resolve(filePath)];
const event = require(filePath);
client.on(event.name, (...args) => event.run(...args, client));
console.log(`Event ${event.name} loaded`);
count++;
}
});
}
loadEvents('../events');
console.log(`Event => ${count} chargé sur le bot`)
}
loadEvents("../events");
console.log(`Event => ${count} chargé sur le bot\n`);
};
+5 -8
View File
@@ -1,15 +1,12 @@
require('dotenv').config();
const { Client, IntentsBitField, Collection } = require("discord.js");
const loadCommands = require("./loaders/loadCommands")
const loadCommands = require("./loaders/loadCommands");
const loadEvents = require("./loaders/loadEvents");
const client = new Client({intents: new IntentsBitField(3276799)});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
(async () => {
await loadCommands(client);
await loadEvents(client);
loadCommands(client);
loadEvents(client);
await client.login(process.env.TOKEN);
})();
client.login(process.env.TOKEN);
})();