fix: Add support for sending client ready, reconnect and disconnect events to system channel

This commit is contained in:
Marius Begby committed 2023-07-17 22:49:37 +02:00
1 parent fab043a308
commit 6fdd943e56
4 files changed
+47 -1

No files matched your search

+2
View File
@@ -9,6 +9,8 @@
"Server id where system commands can be used", "Server id where system commands can be used",
"Another server id where system commands can be used" "Another server id where system commands can be used"
], ],
"systemMessageChannelId": "",
"systemUserId": "",
"embedColors": { "embedColors": {
"colorSuccess": "#23A55A", "colorSuccess": "#23A55A",
"colorWarning": "#F0B232", "colorWarning": "#F0B232",
+16
View File
@@ -1,5 +1,7 @@
const path = require('node:path'); const path = require('node:path');
const logger = require(path.resolve('./src/services/logger.js')); const logger = require(path.resolve('./src/services/logger.js'));
const { EmbedBuilder } = require('discord.js');
const { systemMessageChannelId, systemUserId, embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = { module.exports = {
name: 'disconnect', name: 'disconnect',
@@ -7,5 +9,19 @@ module.exports = {
once: false, once: false,
execute: async (client) => { execute: async (client) => {
logger.warn(`${client.user.tag} lost connection to Discord APIs. Disconnected.`); logger.warn(`${client.user.tag} lost connection to Discord APIs. Disconnected.`);
// send message to system message channel for event
if (systemMessageChannelId && systemUserId) {
await client.channels.cache.get(systemMessageChannelId).send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedIcons.warning} **${client.user.tag}** is **\`disconnected\`**!` +
`\n<@${systemUserId}>`
)
.setColor(embedColors.colorWarning)
]
});
}
} }
}; };
+13 -1
View File
@@ -1,7 +1,8 @@
const path = require('node:path'); const path = require('node:path');
const logger = require(path.resolve('./src/services/logger.js')); const logger = require(path.resolve('./src/services/logger.js'));
const { Events, ActivityType, PresenceUpdateStatus } = require('discord.js'); const { Events, ActivityType, PresenceUpdateStatus, EmbedBuilder } = require('discord.js');
const { postBotStats } = require(path.resolve('./src/utils/postBotStats.js')); const { postBotStats } = require(path.resolve('./src/utils/postBotStats.js'));
const { systemMessageChannelId, embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = { module.exports = {
name: Events.ClientReady, name: Events.ClientReady,
@@ -21,5 +22,16 @@ module.exports = {
// Post bot stats to bot lists in production // Post bot stats to bot lists in production
process.env.NODE_ENV === 'production' ? postBotStats(client) : null; process.env.NODE_ENV === 'production' ? postBotStats(client) : null;
// send message to system message channel for event
if (systemMessageChannelId) {
await client.channels.cache.get(systemMessageChannelId).send({
embeds: [
new EmbedBuilder()
.setDescription(`${embedIcons.success} **${client.user.tag}** is now **\`online\`**!`)
.setColor(embedColors.colorSuccess)
]
});
}
} }
}; };
+16
View File
@@ -1,5 +1,7 @@
const path = require('node:path'); const path = require('node:path');
const logger = require(path.resolve('./src/services/logger.js')); const logger = require(path.resolve('./src/services/logger.js'));
const { EmbedBuilder } = require('discord.js');
const { systemMessageChannelId, systemUserId, embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = { module.exports = {
name: 'reconnecting', name: 'reconnecting',
@@ -7,5 +9,19 @@ module.exports = {
once: false, once: false,
execute: async (client) => { execute: async (client) => {
logger.warn(`${client.user.tag} is reconnecting to Discord APIs.`); logger.warn(`${client.user.tag} is reconnecting to Discord APIs.`);
// send message to system message channel for event
if (systemMessageChannelId && systemUserId) {
await client.channels.cache.get(systemMessageChannelId).send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedIcons.warning} **${client.user.tag}** is **\`reconnecting\`**!` +
`\n<@${systemUserId}>`
)
.setColor(embedColors.colorWarning)
]
});
}
} }
}; };