Rewrite the bot process in js using discord.js

This commit is contained in:
Katie Macke 2021-03-30 00:06:59 -04:00
parent 55bc84e045
commit 3d61792d6c
5 changed files with 103 additions and 1 deletions

27
packages/bot/bot.js Normal file
View file

@ -0,0 +1,27 @@
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);

9
packages/bot/index.js Normal file
View file

@ -0,0 +1,9 @@
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../../.env') });
const { ShardingManager } = require('discord.js');
const botToken = process.env['BOT_TOKEN'];
const manager = new ShardingManager('./bot.js', { token: botToken });
manager.spawn();

10
packages/bot/package.json Normal file
View file

@ -0,0 +1,10 @@
{
"name": "@roleypoly/bot",
"version": "0.1.0",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "^12.5.1"
}
}