Haha-Yes/events/client/guildDelete.js

55 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-08-15 17:26:11 +02:00
import db from '../../models/index.js';
const guildBlacklist = db.guildBlacklist;
2022-08-28 17:04:11 +02:00
import { EmbedBuilder } from 'discord.js';
2022-08-15 17:26:11 +02:00
const { statusChannel, NODE_ENV } = process.env;
2022-08-15 17:26:11 +02:00
export default {
name: 'guildDelete',
async execute(guild, client) {
const guildOwner = await client.users.fetch(guild.ownerId);
2023-04-04 00:45:43 +02:00
const isOptOut = await db.optout.findOne({ where: { userID: guildOwner.id } });
if (isOptOut) {
console.log(`***BOT KICKED***A guild\n${guild.memberCount} users\n***BOT KICKED***`);
if (statusChannel && NODE_ENV !== 'development') {
const channel = client.channels.resolve(statusChannel);
channel.send({ content: `An anonymous guild just removed me.\nI'm now in ${client.guilds.cache.size} servers!` });
}
return;
}
2022-08-15 17:26:11 +02:00
console.log(`***BOT KICKED***\n${guild.name}\n${guild.memberCount} users\nOwner: ${guildOwner.username}\nOwner ID: ${guild.ownerId}\n***BOT KICKED***`);
const blacklist = await guildBlacklist.findOne({ where: { guildID:guild.id } });
// If stats channel settings exist, send bot stats to it
if (statusChannel && NODE_ENV !== 'development') {
2022-08-15 17:26:11 +02:00
const channel = client.channels.resolve(statusChannel);
const botCount = guild.members.cache.filter(member => member.user.bot).size;
console.log(guild.memberCount);
2022-08-28 17:04:11 +02:00
const kickEmbed = new EmbedBuilder()
2022-08-15 17:26:11 +02:00
.setColor('#FF0000')
.setTitle('Some mofo just removed me from there guild :(')
.setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4')
.setThumbnail(guild.iconURL())
2022-08-28 17:04:11 +02:00
.addFields(
{ name: 'Guild', value: `${guild.name} (${guild.id})` },
{ name: 'Total number of members', value: guild.memberCount.toString(), inline: true },
{ name: 'Number of users', value: (guild.memberCount - botCount).toString(), inline: true },
{ name: 'Number of bots', value: botCount.toString(), inline: true },
{ name: 'Owner', value: `${guildOwner.username} (${guild.ownerId})`, inline: true },
)
2022-08-15 17:26:11 +02:00
.setFooter({ text: `I'm now in ${client.guilds.cache.size} servers!` })
.setTimestamp();
if (blacklist) {
kickEmbed.setFooter({ text: kickEmbed.footer.text + ' | Left this guild because owner is blacklisted!' });
}
channel.send({ embeds: [kickEmbed] });
}
},
};