chomens-bot-js/index.js
2022-12-30 16:20:12 +07:00

28 lines
886 B
JavaScript

const readline = require('node:readline')
const { stdin: input, stdout: output } = require('node:process')
const rl = readline.createInterface({ input, output })
const config = require('./config')
const { createBot } = require('./bot')
const { Client, GatewayIntentBits } = require('discord.js')
const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits
const dcclient = new Client({ intents: [Guilds, GuildMessages, MessageContent] })
let bots = []
dcclient.on('ready', () => {
config.servers.forEach(async (server) => {
const getBots = () => bots
const setNewBot = (server, bot) => {
bots = bots.filter((eachBot) => eachBot !== server)
bots.push(bot)
}
createBot(server, config, getBots, setNewBot, dcclient, rl)
})
})
dcclient.login(config.discord.token)
process.on('uncaughtException', (e) => {
console.log('uncaught ' + e.stack)
})