Add support for discord chat bot to announce when images are set, with instructions on configuring for dev
This commit is contained in:
24
app/api/src/lib/discord.ts
Normal file
24
app/api/src/lib/discord.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {Client, Intents} from "discord.js"
|
||||
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})
|
||||
|
||||
export async function sendChat(text: 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);
|
||||
channel.send(text);
|
||||
}
|
||||
}
|
||||
|
||||
client.on("ready", async () => {
|
||||
console.log(`Discord: logged in as ${client.user.tag}`)
|
||||
await sendChat("started");
|
||||
})
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user