Discord.js尝试创buildaddmod命令的问题

您好我目前使用Discord.js创build我自己的不和谐机器人,并在命令行中使用node.jstesting

我想知道是否有人可以帮助我创build一个只有“MODS”可以使用的命令,我在谈论机器人MOD,所以机器人的所有者可以做+ addmod USER将该用户添加到一些数据文件,机器人将从当他们运行“Mod only”命令时,检查用户是否在上面。

链接到源代码: https : //ghostbin.com/paste/tnovx

这不是复杂。 如果你想从文本文件中检查,使用fs模块并将其与机器人function相结合。 我希望这能让你对如何做到一点点洞察力。

 var fs = require('fs'); const Discord = require('discord.js'); var client = new Discord.Client(); client.login('mybot@example.com', '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"); } }); 

你的txt文件应该是这样的,把它们都放到一个新的行,因为我已经使用split()函数,或者如果你有更好的主意,你也可以使用它

users.txt

 user1Name Josh thePredator user2