mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-15 17:19:10 +00:00
Rewrite the bot process in Node/Discord.js (#206)
* Rewrite the bot process in js using discord.js * remove old go code
This commit is contained in:
parent
55bc84e045
commit
7ec603cf70
23 changed files with 104 additions and 799 deletions
27
packages/bot/bot.js
Normal file
27
packages/bot/bot.js
Normal 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
9
packages/bot/index.js
Normal 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
10
packages/bot/package.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "@roleypoly/bot",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"discord.js": "^12.5.1"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue