-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
123 lines (91 loc) · 3.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Requires the necessary discord.js classes.
const {
Discord,
Client,
GatewayIntentBits,
Partials,
Collections,
ChannelType
} = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel
]
});
// Required custom node modules and files.
const config = require('./config.json');
const chalk = require('chalk');
// ========== CONSOLE LOGS STARTS HERE ==========
client.on("ready", async function() {
// Cache shortcuts to make code convenient and short.
const GuildsCache = client.guilds.cache;
const ChannelsCache = client.channels.cache;
// Things which are actually going to get logged.
const Username = client.user.tag;
const UserId = client.user.id;
const Guilds = GuildsCache.map(guild => guild.name);
const GuildsCount = GuildsCache.size;
const GuildsIds = GuildsCache.map(guild => guild.id);
const GuildMembersCount = GuildsCache.map(guild => guild.memberCount);
const TotalMembersCount = GuildMembersCount.reduce((a, b) => a + b, 0);
const ChannelsCount = ChannelsCache.size;
const LogChannel = ChannelsCache.get(config.logChannel);
// Console logs.
console.log(`\n~ Logged in as`, chalk.black.bgGreen(`${Username}`), chalk.black.bgGreen(`${UserId}`));
console.log(`~ Total`, chalk.green.bgBlack(`${GuildsCount}`), `Guilds`);
console.log(`~ Total`, chalk.green.bgBlack(`${ChannelsCount}`), `Channels`);
console.log(`~ Total`, chalk.green.bgBlack(`${TotalMembersCount}`), `Members\n`);
/*
// These three logs can be too big to get logged, write them at your own risk.
console.log(Guilds, `\n`);
console.log(GuildsIds, `\n`);
console.log(GuildMembersCount, `\n`);
*/
// Status and Activity.
client.user.setStatus('dnd');
client.user.setActivity(`${GuildsCount} guilds, ${ChannelsCount} channels, total ${TotalMembersCount} members`);
LogChannel.send('i came online');
});
// ========== CONSOLE LOGS ENDS HERE ==========
// ========== MESSAGE LOGS STARTS HERE ==========
// Guild message logger
client.on('messageCreate', (message) => {
const RoleTheme = chalk.hex('#000').bgHex(`${message.member?.displayHexColor}`);
if (message.author.bot) return
if (message.member?.displayHexColor === '#000000') return
if (message.channel.type === ChannelType.GuildText) {
console.log(RoleTheme(`${message.author.tag}`)+` in #${message.channel.name}\n`+`${message.content} \n`);
}
});
// Guild message logger if the role color is black
client.on('messageCreate', (message) => {
const NoTheme = chalk.hex('#000').bgHex('#fff');
if (message.author.bot) return
if (message.member?.displayHexColor === '#000000') {
console.log(NoTheme(`${message.author.tag}`)+` in #${message.channel.name}\n`+`${message.content} \n`);
}
});
// DMs message logger
client.on('messageCreate', (message) => {
const DMTheme = chalk.hex('#fff').bgHex('#828282');
if (message.author.bot) return
if (message.channel.type === ChannelType.Dm) {
console.log(DMTheme(`${message.author.tag}`)+` in dms\n`+`${message.content} \n`);
}
});
// ========== MESSAGE LOGS ENDS HERE ==========
// ========== TEXT COMMANDS STARTS HERE ==========
// A simple ping command.
client.on('messageCreate', (message) => {
if (message.content.toLowerCase() === 'ping') {
message.reply('pong');
}
});
// ========== TEXT COMMANDS ENDS HERE ==========
// Login to Discord with your bot token in 'config.json' file.
client.login(config.token)