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 () => {
|
client.once('ready', async () => {
|
||||||
console.log(`Logged in as ${client.user.tag} `)
|
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)
|
startBirthdayCheckCron(client)
|
||||||
startEventCheckCron(client)
|
startEventCheckCron(client)
|
||||||
updateGlobalMessage(client)
|
updateGlobalMessage(client)
|
||||||
//initReactionPerRole(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 () => {
|
const connectDiscord = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('Started refreshing application (/) commands.')
|
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()) {
|
for (const [_, oauthGuild] of await client.guilds.fetch()) {
|
||||||
const guild = await oauthGuild.fetch()
|
const guild = await oauthGuild.fetch()
|
||||||
const channel = (await guild.channels.fetch()).find(ch => ch.name === 'reminder')
|
const channel = (await guild.channels.fetch()).find(ch => ch.name === 'reminder')
|
||||||
|
|
||||||
if (!channel) continue
|
if (!channel) continue
|
||||||
|
|
||||||
try {
|
for (let index = 0; index < 10; index++) {
|
||||||
const messages = await channel.messages.fetch({ limit: 1000 })
|
try {
|
||||||
messages.forEach(async (message) => {
|
const messages = await channel.messages.fetch({ limit: 100 })
|
||||||
await message.delete().catch(console.error)
|
messages.forEach(async (message) => {
|
||||||
})
|
await message.delete().catch(console.error)
|
||||||
} catch (error) {
|
})
|
||||||
console.error('Error clearing messages:', error)
|
} catch (error) {
|
||||||
|
console.error('Error clearing messages:', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user