这不是太复杂。如果您想从文本文件中检查,请使用fs
模块并将其与机器人功能结合使用。我希望这能够让你对如何完成这件事有一点认识。
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");
}
});
你的txt文件应该是这样的,把他们都到一个新行,因为我已经使用split()
功能,或者如果你有更好的主意,你可以使用太
users.txt
user1Name
Josh
thePredator
user2
我有点困惑,当一个MOD命令输入聊天时,机器人会运行一些东西,对吗?如果可以,我可以帮忙吗? – turmuka
@turmuka是的,但用户必须使用+ addmod USERNAME添加到mod列表中,然后bot会检查它们是否在文本文件或somthing上。 – Ryan