fixed bye message

This commit is contained in:
Lukian LEIZOUR 2024-12-27 00:45:23 +01:00
parent f37f0d492a
commit f062c0e5c2
6 changed files with 59 additions and 16 deletions

View file

@ -38,7 +38,7 @@ export default {
setFeature(connection, guild_id, feature ? feature : "", "false"); setFeature(connection, guild_id, feature ? feature : "", "false");
connection.end() await connection.end()
const embed = successEmbed("The feature has been successfully disabled.", interaction.client.user.displayAvatarURL()) const embed = successEmbed("The feature has been successfully disabled.", interaction.client.user.displayAvatarURL())

View file

@ -37,7 +37,7 @@ export default {
const feature: string | null = interaction.options.getString("feature") const feature: string | null = interaction.options.getString("feature")
setFeature(connection, guild_id, feature ? feature : "", "true"); await setFeature(connection, guild_id, feature ? feature : "", "true");
connection.end() connection.end()

View file

@ -20,7 +20,7 @@ export default {
const connection = await connectToDb(); const connection = await connectToDb();
const guild: any[] = await getGuild(connection, guild_id); const guild = await getGuild(connection, guild_id);
if (!guild[0]) { if (!guild[0]) {
await addGuild(connection, guild_id); await addGuild(connection, guild_id);

View file

@ -4,7 +4,7 @@ import { createWelcomeImage } from "../libs/imageGeneration.ts"
export default { export default {
name: Events.GuildMemberAdd, name: Events.GuildMemberAdd,
async execute(member: GuildMember ) { async execute(member: GuildMember) {
const connection = await connectToDb(); const connection = await connectToDb();
const guild = await getGuild(connection, member.guild.id); const guild = await getGuild(connection, member.guild.id);
const config = await getWelcomeConfig(connection, member.guild.id); const config = await getWelcomeConfig(connection, member.guild.id);
@ -19,20 +19,18 @@ export default {
} }
if (config[0].description_format) { if (config[0].description_format) {
embed.setDescription(config[0].description_format.replace("{user}", `<@${member.user.id}>`).replace("{welcomer}", `<@&${config[0].welcomer_role_id ? config[0].welcomer_role_id : ""}>`)); embed.setDescription(config[0].description_format.replace("{user}", `<@${member.user.id}>`).replace("{role}", `<@&${config[0].role_id ? config[0].role_id : ""}>`));
} }
if (config[0].vignette_url) { if (config[0].vignette_url) {
embed.setThumbnail(config[0].vignette_url); embed.setThumbnail(config[0].vignette_url);
} }
var attachement;
var buffer;
var files = []; var files = [];
if (config[0].background_url) { if (config[0].background_url) {
buffer = await createWelcomeImage(config[0].background_url, `https://cdn.discordapp.com/avatars/${member.user.id}/${member.user.avatar}.jpeg`, member.user.id); const buffer = await createWelcomeImage(config[0].background_url, `https://cdn.discordapp.com/avatars/${member.user.id}/${member.user.avatar}.jpeg`, member.user.id);
attachement = new AttachmentBuilder(buffer, { name: `${member.user.id}.png` }) const attachement = new AttachmentBuilder(buffer, { name: `${member.user.id}.png` })
files.push(attachement) files.push(attachement)
embed.setImage(`attachment://${member.user.id}.png`) embed.setImage(`attachment://${member.user.id}.png`)
} }
@ -40,7 +38,7 @@ export default {
const channel = member.guild.channels.cache.get(config[0].channel_id); const channel = member.guild.channels.cache.get(config[0].channel_id);
if (channel?.isTextBased()) { if (channel?.isTextBased()) {
channel.send({content: config[0].message_format ? config[0].message_format.replace("{user}", `<@${member.user.id}>`).replace("{welcomer}", `<@&${config[0].welcomer_role_id ? config[0].welcomer_role_id : ""}>`) : "", embeds: [embed], files: files}); channel.send({content: config[0].message_format ? config[0].message_format.replace("{user}", `<@${member.user.id}>`).replace("{role}", `<@&${config[0].role_id ? config[0].role_id : ""}>`) : "", embeds: [embed], files: files});
} }
} }
}, },

View file

@ -0,0 +1,45 @@
import { Events, GuildMember, EmbedBuilder, AttachmentBuilder } from "npm:discord.js";
import { connectToDb, getGuild, getByeConfig } from "../libs/mysql.ts";
import { createWelcomeImage } from "../libs/imageGeneration.ts"
export default {
name: Events.GuildMemberRemove,
async execute(member: GuildMember) {
const connection = await connectToDb();
const guild = await getGuild(connection, member.guild.id);
const config = await getByeConfig(connection, member.guild.id);
connection.end();
if (guild[0]?.welcome_message && config[0]) {
const embed = new EmbedBuilder();
if (config[0].title) {
embed.setTitle(config[0].title);
}
if (config[0].description_format) {
embed.setDescription(config[0].description_format.replace("{user}", `<@${member.user.id}>`).replace("{role}", `<@&${config[0].role_id ? config[0].role_id : ""}>`));
}
if (config[0].vignette_url) {
embed.setThumbnail(config[0].vignette_url);
}
var files = [];
if (config[0].background_url) {
const buffer = await createWelcomeImage(config[0].background_url, `https://cdn.discordapp.com/avatars/${member.user.id}/${member.user.avatar}.jpeg`, member.user.id);
const attachement = new AttachmentBuilder(buffer, { name: `${member.user.id}.png` })
files.push(attachement)
embed.setImage(`attachment://${member.user.id}.png`)
}
const channel = member.guild.channels.cache.get(config[0].channel_id);
if (channel?.isTextBased()) {
channel.send({content: config[0].message_format ? config[0].message_format.replace("{user}", `<@${member.user.id}>`).replace("{role}", `<@&${config[0].role_id ? config[0].role_id : ""}>`) : "", embeds: [embed], files: files});
}
}
},
};

View file

@ -1,8 +1,7 @@
import * as fs from 'node:fs'; import * as fs from 'node:fs';
import * as path from 'node:path';
import "dotenv/config"; import "dotenv/config";
import { Client, Collection, REST, Routes, RESTPutAPIApplicationCommandsResult, GatewayIntentBits, Partials } from 'npm:discord.js'; import { Client, Collection, REST, Routes, GatewayIntentBits, Partials } from 'npm:discord.js';
import { sendLog } from './libs/discord.ts'; import process from 'node:process';
const client: Client = new Client({ const client: Client = new Client({
intents: [ intents: [
@ -10,7 +9,8 @@ const client: Client = new Client({
GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent, GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMembers GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences
], ],
partials: [ partials: [
Partials.Channel, Partials.Channel,
@ -72,7 +72,7 @@ const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD
try { try {
console.log(`Started refreshing ${commands.length} application (/) commands.`); console.log(`Started refreshing ${commands.length} application (/) commands.`);
const data = await rest.put( await rest.put(
Routes.applicationCommands(process.env.BOT_ID ? process.env.BOT_ID : ""), Routes.applicationCommands(process.env.BOT_ID ? process.env.BOT_ID : ""),
{ body: commands } { body: commands }
); );