0
votes

Hi I am currently using Discord.js to create my own discord bot and testing in the command line using node.js

I was wondering if anybody could help me create a command that only "Mods" could use, Im talking about bot mods so a owner of the bot could do +addmod USER to add that user to some data file that the bot would pull from to check if the user was on it when they ran a "Mod only" command.

Link to source-code: https://ghostbin.com/paste/tnovx

1
I am a little bit confused, when a command is typed in to the chat by a mod, the bots will run something, am I right? if so I can help?turmuka
@turmuka Yes but the user must be added to the mod list using +addmod USERNAME then bot will check if they are on the textfile or somthing.Ryan

1 Answers

0
votes

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