maintenance-bot/modules/notifiers/discord.js

28 lines
938 B
JavaScript
Raw Permalink Normal View History

2022-05-27 14:48:43 +02:00
import { Client, Intents } from "discord.js"
import settings from "../../libs/settings.js"
import getLogger from "../../libs/logger.js"
const log = getLogger("Discord", settings.notifiers.discord.color)
export async function start() {
log("Starting Discord notifier...")
const client = new Client({ intents: [ Intents.FLAGS.DIRECT_MESSAGES ]})
async function sendMessage(msg) {
const receivers = await Promise.all(settings.notifiers.discord.receivers.map(id => client.users.fetch(id)))
2022-05-27 14:55:32 +02:00
log("Sending messages to:", receivers.map(e => e.tag), "\nMessage:", msg)
2022-05-27 14:48:43 +02:00
receivers.forEach(async receiver => {
await receiver.createDM()
await receiver.send(msg)
})
}
client.once("ready", () => {
log(`Logged in as ${client.user.username}`)
})
await client.login(settings.notifiers.discord["api-token"])
return sendMessage
}