made bot leave all servers it shouldn't be in

This commit is contained in:
Rene Kievits
2024-12-20 01:03:35 +01:00
parent 0333a2501f
commit ef3399c7ef
2 changed files with 32 additions and 8 deletions

View File

@@ -236,12 +236,34 @@ client.on('messageReactionRemove', async (reaction, user) => {
client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag} `)
const unauthorizedGuilds = client.guilds.cache.filter(guild => guild.id !== process.env.SERVER_ID)
const leavePromises = unauthorizedGuilds.map(async guild => {
console.log(`Leaving unauthorized server: ${guild.id}`);
await guild.leave();
})
await Promise.all(leavePromises)
startBirthdayCheckCron(client)
startEventCheckCron(client)
updateGlobalMessage(client)
//initReactionPerRole(client)
})
client.on('guildCreate', guild => {
if (guild.id !== process.env.SERVER_ID) {
console.log(`Unauthorized server joined: ${guild.name} (${guild.id})`)
guild.leave()
.then(() => console.log(`Left unauthorized server: ${guild.name}`))
.catch(console.error)
}
})
client.on('guildDelete', guild => {
console.log(`Bot removed from server: ${guild.name} (${guild.id})`)
})
const connectDiscord = async () => {
try {
console.log('Started refreshing application (/) commands.')

View File

@@ -69,15 +69,16 @@ const startEventCheckCron = async (client) => {
})
}
})
cron.schedule('0 6 * * *', async () => {
cron.schedule('0 7 * * *', async () => {
for (const [_, oauthGuild] of await client.guilds.fetch()) {
const guild = await oauthGuild.fetch()
const channel = (await guild.channels.fetch()).find(ch => ch.name === 'reminder')
if (!channel) continue
for (let index = 0; index < 10; index++) {
try {
const messages = await channel.messages.fetch({ limit: 1000 })
const messages = await channel.messages.fetch({ limit: 100 })
messages.forEach(async (message) => {
await message.delete().catch(console.error)
})
@@ -85,6 +86,7 @@ const startEventCheckCron = async (client) => {
console.error('Error clearing messages:', error)
}
}
}
})
}