v3/packages/bot/bot.js
Katie Macke 7ec603cf70
Rewrite the bot process in Node/Discord.js (#206)
* Rewrite the bot process in js using discord.js

* remove old go code
2021-03-31 15:35:07 -04:00

27 lines
787 B
JavaScript

const { Client } = require('discord.js');
const botToken = process.env['BOT_TOKEN'];
const allowedBots = process.env['ALLOWED_BOTS']?.split(',') ?? [];
const appUrl = process.env['UI_PUBLIC_URI'] ?? '';
function messageEventListener(message) {
const { author, channel, client, guild, mentions } = message;
if (!guild) {
return;
} // Ignore DMs
if (client.user && !mentions.has(client.user.id)) {
return;
} // Ignore non bot mentions
if (author.bot && !allowedBots.includes(author.id)) {
return;
} // Only respond to allowed bots
const guildId = guild.id;
channel.send(`:beginner: Assign your roles here! ${appUrl}/s/${guildId}`);
}
const client = new Client();
client.on('message', (message) => messageEventListener(message));
client.login(botToken);