made bot leave all servers it shouldn't be in
This commit is contained in:
@@ -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.')
|
||||
|
||||
@@ -69,20 +69,22 @@ 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
|
||||
|
||||
try {
|
||||
const messages = await channel.messages.fetch({ limit: 1000 })
|
||||
messages.forEach(async (message) => {
|
||||
await message.delete().catch(console.error)
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error clearing messages:', error)
|
||||
for (let index = 0; index < 10; index++) {
|
||||
try {
|
||||
const messages = await channel.messages.fetch({ limit: 100 })
|
||||
messages.forEach(async (message) => {
|
||||
await message.delete().catch(console.error)
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error clearing messages:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user