diff --git a/.gitignore b/.gitignore index 197efce..ce2ce65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ config.json templates.file node_modules -package-lock.json \ No newline at end of file +package-lock.json +guilds-*.txt \ No newline at end of file diff --git a/commands/supportBot.js b/commands/supportBot.js index 9b32d31..51bad3e 100644 --- a/commands/supportBot.js +++ b/commands/supportBot.js @@ -1,3 +1,4 @@ +const { EmbedBuilder } = require('discord.js'); module.exports = { name: 'supportbot', description: 'How to support bot development?', diff --git a/events/leaveGuild.js b/events/leaveGuild.js new file mode 100644 index 0000000..ab64f30 --- /dev/null +++ b/events/leaveGuild.js @@ -0,0 +1,14 @@ +const { Events } = require('discord.js'); +const fs = require('fs'); + +module.exports = { + name: Events.GuildDelete, + once: false, + execute(args) { + console.log(`Left guild ${args.name}`); + //guilds-YYYY-MM.txt + const guildPath = `./guilds-${new Date().toISOString().split('T')[0]}.txt`; + //save name - id - time of leaving + fs.appendFileSync(guildPath, `LEAVE: \`${args.name}\` - ${args.id} - ${new Date().toLocaleString()}\n`); + } +}; \ No newline at end of file diff --git a/events/newGuild.js b/events/newGuild.js index 9ca0ef8..5ab6c43 100644 --- a/events/newGuild.js +++ b/events/newGuild.js @@ -1,9 +1,13 @@ const { Events } = require('discord.js'); +const fs = require('fs'); module.exports = { name: Events.GuildCreate, once: false, execute(guild) { console.log(`Joined guild ${guild.name}`); + const guildPath = `./guilds-${new Date().toISOString().split('T')[0]}.txt`; + //save name - id - time of joining + fs.appendFileSync(guildPath, `JOIN: \`${guild.name}\` - ${guild.id} - ${new Date().toLocaleString()}\n`); } }; \ No newline at end of file diff --git a/events/newMember.js b/events/newMember.js new file mode 100644 index 0000000..61554be --- /dev/null +++ b/events/newMember.js @@ -0,0 +1,28 @@ +const { Events, EmbedBuilder } = require('discord.js'); +function randomColor() { + const r = Math.floor(Math.random() * 200) + 50; + const g = Math.floor(Math.random() * 200) + 50; + const b = Math.floor(Math.random() * 200) + 50; + return `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`; +} +module.exports = { + name: Events.GuildMemberAdd, + once: false, + execute(args) { + const { guild, user } = args; + const channel = guild.channels.cache.find(channel => ['new-member', 'new-users', 'hello', 'welcome'].includes(channel.name)); + //find rules channel + const rulesChannel = guild.channels.cache.find(channel => ['rules', 'regulations', 'regulamin'].includes(channel.name)); + if (!channel) return; + if(!rulesChannel) var text = 'Please read the rules in rules channel.'; + else var text = `Please read the rules in ${rulesChannel} channel.`; + const embed = new EmbedBuilder() + .setTitle(`Welcome ${user.username}!`) + .setDescription(`Welcome to ${guild.name}! \n${text}`) + .setColor(randomColor()) + .setThumbnail(user.avatarURL()) + .setTimestamp(); + channel.send({ embeds: [embed] }); + + } +}; \ No newline at end of file diff --git a/index.js b/index.js index 8a77d4d..e42b79e 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,11 @@ const client = new Client({ GatewayIntentBits.GuildMessageTyping, GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessageReactions, - GatewayIntentBits.DirectMessageTyping + GatewayIntentBits.DirectMessageTyping, + GatewayIntentBits.GuildModeration, + GatewayIntentBits.GuildInvites, + GatewayIntentBits.GuildPresences, + GatewayIntentBits.GuildIntegrations ] }); diff --git a/nodemon.json b/nodemon.json index 12e8bb7..a05141c 100644 --- a/nodemon.json +++ b/nodemon.json @@ -1,5 +1,5 @@ { - "watch": ["commands", "deploy-commands.js", "index.js"], + "watch": ["commands", "events", "deploy-commands.js", "index.js"], "execMap": { "js": "node" },