Bot-2.0/events/newGuild.js

27 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-05-23 09:22:31 +00:00
const { Events } = require('discord.js');
2024-06-15 16:52:42 +00:00
const fs = require('fs');
2024-06-16 08:36:11 +00:00
const { prefix } = require('../config.json');
2024-05-23 09:22:31 +00:00
module.exports = {
name: Events.GuildCreate,
once: false,
execute(guild) {
console.log(`Joined guild ${guild.name}`);
2024-06-15 16:52:42 +00:00
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`);
2024-06-16 08:28:17 +00:00
const guildPath2 = `./guilds/guilds-${guild.id}.json`;
if (!fs.existsSync(guildPath2)) {
2024-06-16 08:36:11 +00:00
fs.writeFileSync(guildPath2, JSON.stringify({ id: guild.id, name: [guild.name], premium: false, prefix: prefix, premium:false, hello: false, goodbye: true, helloChannel: null, goodbyeChannel: null, rulesChannel: null, welcomeMessage: { title: "Say hello", content: "Hello {{USER}}"}, goodbyeMessage: { title: "Say goodbye", content: "Goodbye {{USER}}"}, rulesMessage: null}));
2024-06-16 08:28:17 +00:00
}
else
{
const data = JSON.parse(fs.readFileSync(guildPath2));
if (!data.name.includes(guild.name))
{
data.name.push(guild.name);
fs.writeFileSync(guildPath2, JSON.stringify(data));
}
}
2024-05-23 09:22:31 +00:00
}
};