-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscordBot.js
More file actions
46 lines (39 loc) · 1.31 KB
/
Copy pathdiscordBot.js
File metadata and controls
46 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { Client, GatewayIntentBits } = require('discord.js');
const { loadSecrets } = require("./aws/ssm-helper");
const config = require('config');
const logger = require('./logger')(__filename);
const discordBot = {
discordClient: null,
guildId: null,
channelId: null,
};
async function initDiscordBot() {
const discordClient = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
],
});
let botToken, channelId, serverId = null;
if (process.env.ENVIRONMENT === "local") {
botToken = process.env.BOT_TOKEN;
channelId = process.env.CHANNEL_ID;
serverId = process.env.SERVER_ID;
} else {
const params = await loadSecrets(config.aws.param_store_region, ['/catbytes_webplatform/discord_bot_params'], true, true);
botToken = params['discord_bot_params']['bot_token'];
channelId = params['discord_bot_params']['channel_id'];
serverId = params['discord_bot_params']['server_id'];
}
await discordClient.login(botToken);
discordClient.once('ready', async () => {
try {
discordBot.discordClient = discordClient;
discordBot.guildId = serverId;
discordBot.channelId = channelId;
} catch (err) {
logger.error(err, 'Error initializing Discord bot');
}
});
}
module.exports = { discordBot, initDiscordBot };