Embed color

master
KaKi87 4 years ago
parent 783775f3e3
commit 2c3bd7ba75
  1. 3
      config.example.json
  2. 34
      messageHandler.js

@ -5,7 +5,8 @@
{
"channel": "channel",
"title": "",
"body": ""
"body": "",
"color": "#FFFFFF"
},
{
"channels": [

@ -1,3 +1,5 @@
const Discord = require('discord.js');
const handler = {};
let ClientID = null,
@ -7,31 +9,33 @@ let addTextChannel = (textChannel, title, body) => {
handler[textChannel] = { title, body };
};
let add = (channel, title, body) => {
let add = (channel, title, body, color) => {
switch(Guild.channels.get(channel).type){
case 'category':
Guild.channels.filter(c => c.parentID === channel).forEach(textChannel => {
addTextChannel(textChannel.id, title, body);
addTextChannel(textChannel.id, title, body, color);
});
break;
case 'text':
addTextChannel(channel, title, body);
addTextChannel(channel, title, body, color);
break;
}
};
let sendMessage = channel => {
Guild.channels.get(channel).send({
embed: {
title: handler[channel]['title'],
fields: [
{
name: "** **",
value: handler[channel]['body']
}
]
}
let embed = new Discord.RichEmbed({
title: handler[channel]['title'],
fields: [
{
name: "** **",
value: handler[channel]['body']
}
]
});
if(handler[channel]['color']){
embed.setColor(handler[channel]['color']);
}
Guild.channels.get(channel).send(embed);
};
let deleteLastMessage = (channel, callback) => {
@ -48,9 +52,9 @@ module.exports = {
Guild = guild;
messages.forEach(item => {
if(item['channels']) return item['channels'].forEach(channel => {
add(channel, item['title'], item['body']);
add(channel, item['title'], item['body'], item['color'] || 'DEFAULT');
});
add(item['channel'], item['title'], item['body']);
add(item['channel'], item['title'], item['body'], item['color'] || 'DEFAULT');
});
Object.keys(handler).forEach(channel => deleteLastMessage(Guild.channels.get(channel), () => sendMessage(channel)));
},