Last active
March 15, 2018 21:38
-
-
Save CodingBobby/f36e36dc225859453361c29ece77938f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ——— Recource imports ———————————————————————————————————————————————————————— // | |
// Required libaries | |
const Discord = require("discord.js"); // Discord.js libary | |
// Required files | |
const config = require("./config.json"); // Imports configuration file | |
const servers = require("./servers.json"); // Server settings | |
// ——— Login actions ——————————————————————————————————————————————————————————— // | |
// Setting up bot | |
const version = [`${config.general.version}`, `${config.general.update}`]; // Code version, latest update | |
const disbot = new Discord.Client(); // Creates discord client | |
// Starting bot | |
disbot.login(config.general.token, loginLog()); // Logs in with token & runs log function | |
disbot.on("debug", (m) => console.log(`\n[debug]\n\n`, m)); // Debugs connection | |
disbot.on("warn", (m) => console.log(`\n[warn]\n\n`, m)); // Asks for possible issues | |
disbot.on("ready", () => { // Actions after successful start | |
// Sending feedback to console and log channel | |
let readyLog = `\n>\n> ${disbot.readyTimestamp}\n> Here I am! - <@!${disbot.user.id}> \n> Now serving ${disbot.users.size} users on ${disbot.guilds.size} servers with ${disbot.channels.size} channels!`; | |
console.log(readyLog); | |
const log = disbot.channels.find('id', servers.log); // Creates log from ID in servers.json | |
if(log) // Sends only when log channel was set | |
log.send(readyLog); | |
}); | |
// ——— Global functions ———————————————————————————————————————————————————————— // | |
function loginLog(error, token) { // Gives login feedback and fetches errors | |
if(error) { | |
console.log(`\n>\n> There was an error logging in: ${error}`); | |
return; | |
} else | |
console.log(`\n>\n> Logged in. Token: ${config.general.token}`); | |
} | |
// ——— Message actions ————————————————————————————————————————————————————————— // | |
// Logbook actions | |
disbot.on("message", message => { | |
const guildTag = message.channel.type === 'text' ? `[${message.guild.name}]` : '[DM]'; | |
const channelTag = message.channel.type === 'text' ? `[#${message.channel.name}]` : ''; | |
if(servers.blacklist.indexOf(message.channel.id)) return; // Prevents logging log itself | |
let msgLog = `\n>\n> ${message.createdAt}\n> ${guildTag}${channelTag} ${message.author.tag}\n> \"${message.content}\"`; | |
console.log(msgLog); // Sends log to terminal | |
const log = disbot.channels.find('id', servers.log); // Creates log from ID in servers.json | |
if(log) { | |
msgLog = `\n>\n> ${message.createdAt}\n> **${guildTag}**${channelTag} **${message.author.tag}**\n> \"${message.content}\"`; | |
log.send(msgLog); // Sends only when log channel was set | |
} | |
}); | |
// ————————————————————————————————————————————————————————————————————————————— // |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment