所以我创建了一个不和谐的机器人,我想让它滚动一个随机数(我已经知道如何做)如果滚动高于49,用户可以使用命令"购买"。现在这是我无法编码的部分。如何将特定命令附加到条件。此外,如果玩家低于49,他将无法使用"购买"。
if(command === "shekels"){
var object = (prizes[Math.floor(Math.random()*prizes.length)])
var shekels = Math.floor(Math.random()*99 +1 )
message.channel.send(`You rolled ${shekels} shekels !`)
if(shekels <49){
message.channel.send("Oi you dont have enough shekels to buy at my store *rubs hands*")
}//49 brackets
else{
message.channel.send("Hey you do have enough shekels to buy something from my store")
};
};//command bracket
if(shekels < 49){
message.channel.send("Oi you dont have enough shekels to buy at my store *rubs hands*");
}//49 brackets
else{
allowedUsers.push(message.author.username);
};
if(command === "buy"){
if(!allowedUsers.includes(message.author.username)){
return message.channel.send("You did not roll 49 or above so you cannot use this command.");
}
else{
message.channel.send("here " + objectStore);
};
};
上面的命令^对我不起作用
答案 0 :(得分:0)
为什么不在全局范围内创建可以使用该命令的用户数组?最好使用他们的id。因此当它们在49以上滚动时,它们会被添加到阵列中。然后检查他们是否在使用buy命令时进入。
var allowedUsers = []; //Should be above everything, put it right under your imports (that is, under require("discord.js"))
//Your command handler code
if(command === "shekels"){
var object = (prizes[Math.floor(Math.random()*prizes.length)])
var shekels = Math.floor(Math.random()*99 +1 )
message.channel.send(`You rolled ${shekels} shekels !`)
if(shekels >= 49){
allowedUsers.push(message.author.id);
}
}
if(command === "buy"){
if(!allowedUsers.includes(message.author.id)){
return message.channel.send("You did not roll 49 or above so you cannot use this command.");
}
else{
message.channel.send("here " + objectStore);
};
};