From 237a945470f1c626b9b34d7676a8dcc4efc65bd3 Mon Sep 17 00:00:00 2001 From: BluDood Date: Thu, 3 Nov 2022 21:18:42 +0100 Subject: [PATCH] Join and leave messages --- events/guildMemberAdd.js | 12 ++++++++++++ events/guildMemberRemove.js | 12 ++++++++++++ index.js | 2 +- utils/setup.js | 10 +++++++--- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 events/guildMemberAdd.js create mode 100644 events/guildMemberRemove.js diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js new file mode 100644 index 0000000..62ddc5c --- /dev/null +++ b/events/guildMemberAdd.js @@ -0,0 +1,12 @@ +const { Events } = require('discord.js') +const config = require('../utils/config') + +module.exports = { + event: Events.GuildMemberAdd, + async listener(event) { + if (!config.get().channels.welcome) return + const channel = await event.guild.channels.fetch(config.get().channels.welcome) + if (!channel) return + channel.send(`Hi <@${event.user.id}>, welcome to ${event.guild.name}!`) + } +} diff --git a/events/guildMemberRemove.js b/events/guildMemberRemove.js new file mode 100644 index 0000000..7685b26 --- /dev/null +++ b/events/guildMemberRemove.js @@ -0,0 +1,12 @@ +const { Events } = require('discord.js') +const config = require('../utils/config') + +module.exports = { + event: Events.GuildMemberRemove, + async listener(event) { + if (!config.get().channels.welcome) return + const channel = await event.guild.channels.fetch(config.get().channels.welcome) + if (!channel) return + channel.send(`Goodbye <@${event.user.id}> 👋`) + } +} diff --git a/index.js b/index.js index a4fc228..ea5ae51 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ const { token } = config.get() if (!fs.existsSync('./databases')) fs.mkdirSync('./databases') const client = new Client({ - intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessageReactions] + intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers] }) client.commands = new Collection() diff --git a/utils/setup.js b/utils/setup.js index 7447ace..132ea45 100644 --- a/utils/setup.js +++ b/utils/setup.js @@ -13,7 +13,8 @@ const current = { }, modRoles: [], channels: { - logs: null + logs: null, + welcome: null } } @@ -53,14 +54,17 @@ function readline() { current.customization.colors.bad = await readline() } console.log((customColors === 'y' ? '' : "Alright, i'll use the default colors. ") + 'Now, time to set up your moderation roles. Enter all your moderation role IDs here, separated by a comma.') - current.modRoles = (await readline()).split(',').map(r => parseInt(r.trim())) + current.modRoles = (await readline()).split(',').map(r => r.trim()) console.log("Got that. Now enter the channel you'd like me to send logs to:") - current.channels.logs = parseInt((await readline()).trim()) + current.channels.logs = (await readline()).trim() + console.log("Now enter the channel you'd like me to send welcome message to. Leave blank to disable.") + current.channels.welcome = (await readline()).trim() console.log(` Guild ID: ${current.guildId} Bot token: ${current.token} Moderator Roles: ${current.modRoles.join(', ')} Logging channel: ${current.channels.logs} +Welcome channel: ${current.channels.welcome} Does this look correct? [Y/n] `) const correct = (await readline()).toLowerCase()