first commit
This commit is contained in:
21
events/guildCreate/addGuildToDB.js
Normal file
21
events/guildCreate/addGuildToDB.js
Normal file
@ -0,0 +1,21 @@
|
||||
const { Guild, Events } = require('discord.js');
|
||||
|
||||
const db = require('../../db');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildCreate,
|
||||
async execute(guild) {
|
||||
try {
|
||||
await db.query('CREATE TABLE IF NOT EXISTS guilds (guild_id VARCHAR PRIMARY KEY, guild_name VARCHAR, created_at TIMESTAMP, guild_owner_id VARCHAR)');
|
||||
const result = await db.query('SELECT * FROM guilds WHERE guild_id = $1', [guild.id]);
|
||||
if (result.rows.length === 0) {
|
||||
await db.query('INSERT INTO guilds (guild_id, guild_name, created_at, guild_owner_id) VALUES ($1, $2, $3, $4)', [guild.id, guild.name, guild.createdAt, guild.ownerId]);
|
||||
console.log(`Added new guild to the database: ${guild.name}`);
|
||||
} else {
|
||||
console.log(`Guild already exists in the database: ${guild.name}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error adding guild to the database:', error);
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user