這不是太複雜。如果您想從文本文件中檢查,請使用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