Add greet System

This commit is contained in:
VALOU3336
2024-02-17 08:31:02 +01:00
parent 6c71e7e9b4
commit aa1811a9f1
4 changed files with 104 additions and 1 deletions
+38
View File
@@ -0,0 +1,38 @@
const { EmbedBuilder } = require('discord.js');
const db = require('quick.db');
const GestionDb = new db.table('gestion');
module.exports = {
name: 'greet',
description: 'Ajoute ou supprime un salon des greet',
async execute(message, args) {
const botId = message.client.user.id;
const guildId = message.guild.id;
const guildGreetings = GestionDb.get(`${botId}.${guildId}.greetings`) || [];
const channelId = args[0] ? args[0].replace(/<#|>/g, '') : message.channel.id;
const index = guildGreetings.findIndex(greeting => greeting.channelId === channelId);
if (index !== -1) {
guildGreetings.splice(index, 1);
GestionDb.set(`${botId}.${guildId}.greetings`, guildGreetings);
const embed = new EmbedBuilder()
.setDescription(`Le salon <#${channelId}> a été retiré de la liste des salutations.`)
.setColor('#0099ff');
message.channel.send({ embeds: [embed] });
} else if (guildGreetings.length < 5) {
guildGreetings.push({ channelId });
GestionDb.set(`${botId}.${guildId}.greetings`, guildGreetings);
const embed = new EmbedBuilder()
.setDescription(`Le salon <#${channelId}> a été ajouté à la liste des salutations.`)
.setColor('#0099ff');
message.channel.send({ embeds: [embed] });
} else {
const embed = new EmbedBuilder()
.setDescription('Il y a déjà 5 salons dans la liste des salutations. Vous ne pouvez pas en ajouter d\'autres.')
.setColor('#ff0000');
message.channel.send({ embeds: [embed] });
}
},
};
+28
View File
@@ -0,0 +1,28 @@
const { EmbedBuilder } = require('discord.js');
const db = require('quick.db');
const GestionDb = new db.table('gestion');
module.exports = {
name: 'greetlist',
description: 'Affiche la liste des salons avec un salutation',
async execute(message) {
const botId = message.client.user.id;
const guildId = message.guild.id;
const guildGreetings = GestionDb.get(`${botId}.${guildId}.greetings`) || [];
if (guildGreetings.length === 0) {
const embed = new EmbedBuilder()
.setTitle('Aucun salon avec un salutation')
.setDescription('Il n\'y a aucun salon avec un salutation pour ce serveur.')
.setColor('#ff0000');
message.channel.send({ embeds: [embed] });
} else {
const greetingChannels = guildGreetings.map(greeting => `<#${greeting.channelId}>`).join(', ');
const embed = new EmbedBuilder()
.setTitle(`Salons avec un greet ${guildGreetings.length}/5`)
.setDescription(`${greetingChannels}`)
.setColor('#0099ff');
message.channel.send({ embeds: [embed] });
}
},
};
+35
View File
@@ -0,0 +1,35 @@
const db = require('quick.db');
const GestionDb = new db.table('gestion');
const {Events} = require("discord.js")
module.exports = {
name: Events.GuildMemberAdd ,
async execute(member) {
const botId = member.client.user.id;
const guildId = member.guild.id;
const guildGreetings = GestionDb.get(`${botId}.${guildId}.greetings`) || [];
if (guildGreetings.length > 0) {
const welcomeMessage = `Bienvenue <@${member.id}> sur le serveur ${member.guild.name} !`;
const messagePromises = [];
for (const greeting of guildGreetings) {
try {
const channel = await member.guild.channels.fetch(greeting.channelId);
if (channel && channel.type === 0) {
messagePromises.push(
channel.send(welcomeMessage)
.then(message => {
setTimeout(() => message.delete(), 1000);
})
);
}
} catch (error) {
}
}
try {
await Promise.all(messagePromises);
} catch (error) {
}
}
},
};
+3 -1
View File
@@ -116,5 +116,7 @@
"bl": 10,
"unbl": 10,
"stat": 10,
"random": 0
"random": 0,
"greet": 10,
"greetlist": 10
}