It's not too complicated. If you want to check from a text file, use fs
module and combine it with bots functions. I hope this gives you a little insight on how it could be done.
var fs = require('fs');
const Discord = require('discord.js');
var client = new Discord.Client();
client.login('[email protected]', 'password', callbackOutput);
//get data from file
var fileData = fs.readFileSync(filename); //put eachname to a new line
var userNames = filedata.toString().split('\n'); // gets all the names in an array from all lines
client.on('message', function(message) {
if(message == "myCommand"){
//handle command stuff
for(var i = 0; i < userNames.length; i++){
if(userNames[i] == message.author.name){
var theUserIsMod = true;
console.log(message.author); //info about sender
message.author.userIsMod = true; //set the attribute userIsMod for later
}
}
if(theUserIsMod == true){
//if the user is mod do more stuff
}
else{
console.log("user is not mod");
return false; //exit the program
}
}else{
console.log("command not found");
}
});
Your txt file should be like this, put them all to a new line since I have used split()
function, or if you have any better idea you can use that too
users.txt
user1Name
Josh
thePredator
user2
command
is typed in to the chat by a mod, the bots will run something, am I right? if so I can help? – turmuka