-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
65 lines (51 loc) · 1.9 KB
/
index.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Dependencies
require('dotenv').config({ path: `${__dirname}/.env` })
const Discord = require('discord.js')
// Queue Managment
const { removeOfflinePlayerFromQueue } = require('./utils/managePlayerQueues')
// On Listeners
const { voiceStateUpdateHandler, messageHandler } = require('./onHandlers')
// Discord Bot
const bot = new Discord.Client()
// Bot User Info
let botUser = {}
// Environment Variables
const { token, channelName } = process.env
bot.on('ready', (e) => {
const { username, id } = bot.user
botUser.username = username
botUser.id = id
console.log(`Logged in as: ${username} - ${id}`)
console.log(`I will be listening for messages on your text-channel: ${channelName}`)
console.log('****** (safe) process.env variables ******')
console.log('channelName:', process.env.channelName)
console.log('categoryName:', process.env.categoryName)
console.log('NODE_ENV:', process.env.NODE_ENV)
console.log('lobbySeries', process.env.lobbySeries)
console.log('lobbyRegion', process.env.lobbyRegion)
console.log('lobbyName', process.env.lobbyName)
console.log('****** process.env variables ******')
})
// Handle 6man commands when a user sends the message
bot.on('message', (eventObj) => messageHandler(eventObj, botUser))
// Remove players from the queue if they go offline
// bot.on('presenceUpdate', (oldMember, newMember) => {
// if (newMember.presence.status === 'offline') {
// // Remove this player from the queue if they are in one
// removeOfflinePlayerFromQueue({ playerId: newMember.user.id, playerChannels: newMember.client.channels })
// }
// })
// Delete team voice channels and queues
bot.on('voiceStateUpdate', voiceStateUpdateHandler)
bot.on('disconnect', (e) => {
console.log('Bot disconnected:', e)
})
async function login() {
try {
await bot.login(token)
} catch (err) {
console.error('The bot failed to login:', err)
}
}
login()
module.exports = bot