const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const fs = require('fs');
const path = require('path');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.once('ready', () => {
console.log(Logged in as ${client.user.tag});
});
function loadEmbeds(filename) {
try {
const rawData = fs.readFileSync(path.join(__dirname, 'embeds', filename), 'utf-8');
const jsonData = JSON.parse(rawData);
return jsonData.embeds.map(embedData => {
const embed = new EmbedBuilder()
.setTitle(embedData.title || null)
.setDescription(embedData.description || null)
.setColor(embedData.color || null)
.setFooter(embedData.footer ? { text: embedData.footer.text } : null)
.setTimestamp(embedData.timestamp ? new Date(embedData.timestamp) : null)
.setImage(embedData.image ? embedData.image.url : null);
if (embedData.fields) {
embed.addFields(embedData.fields);
}
return embed;
});
} catch (error) {
console.error(Error loading embed file: ${filename}, error);
return null;
}
}
client.on('messageCreate', message => {
if (!message.content.startsWith('!') || message.author.bot) return;
const commandName = message.content.slice(1).toLowerCase();
const embedFilename = ${commandName}.json;
const embeds = loadEmbeds(embedFilename);
if (embeds) {
message.channel.send({ embeds: embeds }).catch(console.error);
} else {
message.channel.send("This command does not exist or no embed is configured for it.");
}
});
client.login('AAAA');