maintenance-bot/modules/notifiers/discord.js
2022-05-27 14:55:32 +02:00

28 lines
938 B
JavaScript

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)))
log("Sending messages to:", receivers.map(e => e.tag), "\nMessage:", msg)
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
}