From 16d357208fe99206ff5863976a10887ff747250c Mon Sep 17 00:00:00 2001 From: *x1 Date: Tue, 28 May 2024 21:37:53 +0200 Subject: [PATCH] Update event (deso grose pagaille) --- events/guildCreate.js | 3 +-- events/guildMemberAdd.js | 3 +-- events/interactionCreate.js | 5 +++-- events/messageCreate.js | 7 +++---- events/messageCreateLVL.js | 9 +++++---- events/ready.js | 4 ++-- main.js | 35 +++++++++++++++++++++++++++++++---- 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/events/guildCreate.js b/events/guildCreate.js index 2e8e053..249e107 100644 --- a/events/guildCreate.js +++ b/events/guildCreate.js @@ -1,8 +1,7 @@ -const { Events } = require('discord.js'); const db = require('../fonctions/database.js'); module.exports = { - name: Events.GuildCreate, + name: 'guildCreate', async execute(guild) { db.run(`INSERT OR IGNORE INTO config (guildId, name, value) VALUES (?, ?, ?)`, [guild.id, 'prefix', '&']); guild.members.cache.forEach(member => { diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js index 5ea31af..1e1d127 100644 --- a/events/guildMemberAdd.js +++ b/events/guildMemberAdd.js @@ -1,8 +1,7 @@ -const { Events } = require('discord.js'); const db = require('../fonctions/database.js'); module.exports = { - name: Events.GuildMemberAdd, + name: 'guildMemberAdd', async execute(member) { db.run(`INSERT INTO users (guildId, userId) VALUES (?, ?)`, [member.guild.id, member.id]); }, diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 4b205d5..001c6b7 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -1,12 +1,13 @@ -const { Events } = require('discord.js'); +const { EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, StringSelectMenuBuilder } = require("discord.js") const db = require('../fonctions/database.js'); const embedColor = require('../fonctions/embedColor.js'); module.exports = { - name: Events.InteractionCreate, + name: 'interactionCreate', async execute(client, interaction) { if (interaction.customId === "lvl_Recomp_Rep") { + console.log('test ok') const lvl = interaction.message.embeds[0].fields[0].value const serv = interaction.message.embeds[0].fields[1].value diff --git a/events/messageCreate.js b/events/messageCreate.js index 2bf80de..fc40cbc 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -1,11 +1,10 @@ -const { Message, Events } = require("discord.js"); const db = require('../fonctions/database.js'); //const getPermissionLevel = require("../fonctions/getPermissionLevel"); module.exports = { - name: Events.MessageCreate, - async execute(message, client) { - if (message.author.bot) return; + name: 'messageCreate', + async execute(client, message) { + if (message.channel.isDMBased() || message.author.bot) return; const prefix = db.get(`SELECT value FROM config WHERE guildId = ? AND name = ?`, [message.guild.id, 'prefix'])?.value || '&'; if (message.content.startsWith(prefix)) { diff --git a/events/messageCreateLVL.js b/events/messageCreateLVL.js index cb7452d..f19ddf1 100644 --- a/events/messageCreateLVL.js +++ b/events/messageCreateLVL.js @@ -1,9 +1,10 @@ -const { Message, Events, ActionRowBuilder, ActionRow, ButtonBuilder, EmbedBuilder } = require("discord.js"); +const { ActionRowBuilder, ActionRow, ButtonBuilder, ButtonStyle, EmbedBuilder } = require("discord.js"); const db = require('../fonctions/database.js'); +const embedColor = require('../fonctions/embedColor.js'); module.exports = { - name: Events.MessageCreate, - async execute(message, client) { + name: 'messageCreate', + async execute(client, message, args) { if (message.author.bot) return; if (message.content.length < 50) { @@ -25,7 +26,7 @@ module.exports = { const embedlvl = new EmbedBuilder() .setTitle('Nouveau niveau !') - .setDescription('Vous avez passé(e) un niveau sur ' + message.guild.name + ' !!\n\nVeuillez choisir une recompense :') + .setDescription('Vous avez passé(e) un niveau sur **__' + message.guild.name + '__** !!\n\nVeuillez choisir une recompense :') .setColor(await embedColor(message.author.id, message.guild.id)) .setTimestamp() .addFields({ name: 'Le niveau passé :', value: `${user.lvl}`, inline: true }) diff --git a/events/ready.js b/events/ready.js index 0e6098b..b4ecbf4 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,8 +1,8 @@ -const { Events, ActivityType } = require('discord.js'); +const { ActivityType } = require('discord.js'); const db = require('../fonctions/database.js'); module.exports = { - name: Events.ClientReady, + name: 'clientReady', async execute(client) { console.log(`[READY] ${client.user.tag} est prêt ||| ${client.guilds.cache.size.toLocaleString('fr-FR')} serveurs | ${client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0).toLocaleString('fr-FR')} utilisateurs\n`.green); diff --git a/main.js b/main.js index e0047c7..180982c 100644 --- a/main.js +++ b/main.js @@ -1,15 +1,42 @@ -require('dotenv').config(); const { Client, IntentsBitField, Collection } = require("discord.js"); +const client = new Client({ + intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildBans, GatewayIntentBits.GuildEmojisAndStickers, GatewayIntentBits.GuildIntegrations, GatewayIntentBits.GuildWebhooks, GatewayIntentBits.GuildInvites, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMessageTyping, GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessageReactions, GatewayIntentBits.DirectMessageTyping, GatewayIntentBits.GuildScheduledEvents, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent], + partials: [Partials.Channel, Partials.GuildMember, Partials.GuildScheduledEvent, Partials.Message, Partials.Reaction, Partials.ThreadMember, Partials.User], + restTimeOffset: 0, + failIfNotExists: false, + presence: { + activities: [{ + name: `starting...`, + type: ActivityType.Custom, + }], + }, + allowedMentions: { + parse: ["roles", "users", "everyone"], + repliedUser: false + } +}); + +require('dotenv').config(); +const color = require('colors') +const fs = require('fs') + const loadCommands = require("./fonctions/loadCommands"); const loadEvents = require("./fonctions/loadEvents"); -const client = new Client({intents: new IntentsBitField(3276799)}); -const color = require('colors') - client.events = new Collection(); client.commands = new Collection(); client.config = require("./config.json"); console.log(`${loadEvents(client, '..\\events')} events loaded`.grey); +const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js")); +for (const file of eventFiles) { + const event = require(`./events/${file}`); + if (event.once) { + client.once(event.name, (...args) => event.execute(client, ...args)); + } else { + client.on(event.name, (...args) => event.execute(client, ...args)); + } +} + console.log(`${loadCommands(client, '..\\commands')} commands loaded`.grey); client.login(process.env.TOKEN); \ No newline at end of file