discord_bot/server.js
SileNce5k ec456a9b32
Add online message
When the bot comes online, it will send a specified message to a
specified channel. Both specified in config.json
2021-03-11 00:14:49 +01:00

50 lines
No EOL
1.2 KiB
JavaScript

const fs = require('fs')
const Discord = require('discord.js');
const client = new Discord.Client({ disableEveryone: true });
const {
prefix,
token,
loginMessage,
loginChannel
} = require('./config.json');
client.commands = new Discord.Collection();
var reloadCommands = require("./util/reloadCommands.js")
reloadCommands(client)
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity(prefix, { type: 'LISTENING' });
try{
client.channels.cache.get(loginChannel).send(loginMessage)
}catch(err){
console.log("Failed trying to send a message on login.\n")
}
});
client.once('reconnecting', () => {
console.log('Reconnecting!');
});
client.once('disconnect', () => {
console.log('Disconnect!');
});
client.on('message', async message => {
const args = message.content.slice(prefix.length).split(" ")
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName);
if (!message.guild) return;
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
try {
command.execute({message:message, args:args, client: client})
} catch (error) {
console.log(`${error}\n-------`)
}
});
client.login(token);