Creating a Discord bot using node.js and discord.js and am fairly new to JavaScript. I have made a basic bot that works how I want it to, but am looking to find better ways to make the code efficient, yet concise. I have multiple variables that read from text files and was told that an array could help, only knowing basic arrays I couldn't really find tips on how to still make the array elements read from the specified text files.
I don't know much about arrays, so I haven't tried much. I was just told that arrays could help make my code concise.
const Discord = require("discord.js");
const fs = require('fs');
const client = new Discord.Client();
const colors = require("colors");
var help = fs.readFileSync("./text/help.txt", "utf8");
var FUN = fs.readFileSync("./text/fun.txt", "utf8");
var MEME = fs.readFileSync("./text/meme.txt", "utf8");
var hello = fs.readFileSync("./text/hello.txt", "utf8");
var GAMES = fs.readFileSync("./text/games.txt", "utf8");
var music = fs.readFileSync("./text/music.txt", "utf8");
client.on("ready", () => {
console.log(colors.green("Connected as " + client.user.tag));
client.user.setPresence({
'game' : {
'name' : 'Checking...',
'type' : 'Playing'
}
})
try {
client.on("message", function(message) {
var input = message.content.toUpperCase();
if(input === "!help".toUpperCase()) {
message.channel.send(help);
}
if(input === "!FUN".toUpperCase()){
message.channel.send(FUN);
}
if(input === "!MEME".toUpperCase()){
message.channel.send(MEME);
}
if(input === "!hello".toUpperCase()){
message.channel.send(hello);
}
if(input === "!GAMES".toUpperCase()){
message.channel.send(GAMES);
}
if(input === "!music".toUpperCase()){
message.channel.send(music);
}
})
}
catch(E){
console.log(E);
}
})
client.login('token');