diff --git a/_list-guilds.js b/_list-guilds.js new file mode 100644 index 0000000..1a85f44 --- /dev/null +++ b/_list-guilds.js @@ -0,0 +1,31 @@ +/* + * Quick and dirty script to list out what guilds the bot is in and optionally leave some. + */ + +const guildsToLeave = ['1219254855789711432']; + +const dotenv = require('dotenv').config(); +const token = process.env.TOKEN; +const Discord = require('discord.js'); + +const client = new Discord.Client({ + intents: [ + 'GUILDS' + ] +}); + +client.on('ready', async () => { + console.log(`Logged in as ${client.user.tag}`); + console.log('Guilds:'); + client.guilds.cache.forEach(async (guild) => { + console.log(` - ${guild.name} (${guild.id})`); + if (guildsToLeave.includes(guild.id)) { + console.log(` Leaving ${guild.name}`); + await guild.leave(); + } + }); + console.log('Done.'); + client.destroy(); +}); + +client.login(token); \ No newline at end of file diff --git a/main.js b/main.js index c97a05d..e798340 100644 --- a/main.js +++ b/main.js @@ -31,6 +31,7 @@ const { GifData, CommandData } = require('./CustomModules/NodBot.js'); const ButtonHandlers = require('./CustomModules/ButtonHandlers.js'); const InteractionStorage = require('./CustomModules/InteractionStorage.js'); const isDev = process.env.isDev; +let statusChannel; client.once('ready', async () => { fn.collections.interactionStorage(client); @@ -48,9 +49,8 @@ client.once('ready', async () => { await fn.avWx.metar.getAllICAOs(); await fn.avWx.datis.getAllICAOs(); // console.log(JSON.stringify(icaoArray)); - client.channels.fetch(statusChannelId).then(channel => { - channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`); - }); + statusChannel = await client.channels.fetch(statusChannelId).catch(e => console.error(e)); + await channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`).catch(e => console.error(e)); }); // slash-commands @@ -146,4 +146,15 @@ client.on('messageCreate', message => { return; }); +// Guild Joins and Leaves: +client.on('guildCreate', async guild => { + await statusChannel.send(`I've been added to a new guild: ${guild.name} (${guild.id})`) + .catch(e => console.error(e)); +}); + +client.on('guildDelete', async guild => { + await statusChannel.send(`I've been removed from a guild: ${guild.name} (${guild.id})`) + .catch(e => console.error(e)); +}); + client.login(token); \ No newline at end of file