first commit
This commit is contained in:
34
events/guildCreate/createChannel.js
Normal file
34
events/guildCreate/createChannel.js
Normal file
@ -0,0 +1,34 @@
|
||||
const { Guild, Events, PermissionFlagsBits } = require('discord.js');
|
||||
|
||||
const db = require('../../db');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildCreate,
|
||||
async execute(guild) {
|
||||
try {
|
||||
await db.query('CREATE TABLE IF NOT EXISTS bot_channel (guild_id VARCHAR PRIMARY KEY, guild_name VARCHAR, channel_id VARCHAR, channel_name VARCHAR)');
|
||||
const result = await db.query('SELECT * FROM bot_channel WHERE guild_id = $1', [guild.id]);
|
||||
if (result.rows.length === 0) {
|
||||
// Create Channel then add to database
|
||||
const channel = await guild.channels.create({
|
||||
name: 'BluBot',
|
||||
type: 0,
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: guild.id,
|
||||
allow: [PermissionFlagsBits.ViewChannel],
|
||||
},
|
||||
],
|
||||
});
|
||||
await db.query('INSERT INTO bot_channel (guild_id, guild_name, channel_id, channel_name) VALUES ($1, $2, $3, $4)', [guild.id, guild.name, channel.id, channel.name]);
|
||||
//await db.query('INSERT INTO bot_channel (guild_id, guild_name, channel_id, channel_name) VALUES ($1, $2, $3, $4)', [guild.id, guild.name, guild.channels.id, guild.channels.name]);
|
||||
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 creating channel or adding to database:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user