问题描述
例如我选择输入牛肉,然后问一个关于牛肉的问题,如果我输入鸡肉,然后问一个关于鸡肉的问题。
有点像如果用户输入“牛肉”,然后问这个问题。否则,如果用户输入“鸡”,则询问此问题。
解决方法
如果您想为每种特定类型的肉添加一个问题,那么您可以在第一个 if 之后使用和“else if”,如下所示:
const user = message.mentions.users.first() || message.member.user
const userid = guild.members.cache.get(user.id)
const user_file = userid + ".json"
fs.readFile(user_file,'utf8',(err,data) => {
if (err) {console.log("error"),err}
const channel = <client>.channels.cache.get('<id>');
channel.send("file " + user_file + " contains " + data);
})
顺便说一句,当您同时检查“牛肉”和“牛肉”时,您实际上可能想要使用 String response;
if(meatType.equals("beef")) {
// ask question related to beef
System.out.println("beef question...");
// based off your follow up comment:
response = input.nextLine();
} else if (meatType.equals("chicken")) {
// ask question related to chicken
System.out.println("chicken question...");
// based off your follow up comment:
response = input.nextLine();
}
,这样可以节省您添加每个边缘情况。