Discord chat bot to announce projects (#590)

* Add support for discord chat bot to announce when images are set, with instructions on configuring for dev

* Tweak discord bot message.

Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit was merged in pull request #590.
This commit is contained in:
Scott Martin
2022-01-13 15:11:30 -05:00
committed by GitHub
parent 82dd3d2555
commit 90fece9598
7 changed files with 146 additions and 8 deletions

View File

@@ -0,0 +1,34 @@
import {Client, Intents, MessageAttachment} from "discord.js"
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})
export async function sendDiscordMessage(text: string, url?: string) {
if (!client.isReady()) {
console.error(`Discord: client is not ready to send message ("${text}")`);
} else {
const channel = await client.channels.fetch(process.env.DISCORD_CHANNEL_ID);
if (url) {
channel.send({ embeds: [{
title: text,
image: {
url: url,
},
}] });
} else {
channel.send(text)
}
}
}
client.on("ready", async () => {
console.log(`Discord: logged in as ${client.user.tag}`)
})
if (!process.env.DISCORD_TOKEN || !process.env.DISCORD_CHANNEL_ID) {
console.warn("Discord bot not configured - please set process.env.DISCORD_TOKEN and process.env.DISCORD_CHANNEL_ID to send discord chats");
} else {
console.log(`Discord: logging in (token ${process.env.DISCORD_TOKEN})`);
client.login(process.env.DISCORD_TOKEN);
}