微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

是否可以接受用户输入,并根据响应提出不同的问题?

如何解决是否可以接受用户输入,并根据响应提出不同的问题?

enter image description here

例如我选择输入牛肉,然后问一个关于牛肉的问题,如果我输入鸡肉,然后问一个关于鸡肉的问题。

有点像如果用户输入“牛肉”,然后问这个问题。否则,如果用户输入“鸡”,则询问此问题。

解决方法

如果您想为每种特定类型的肉添加一个问题,那么您可以在第一个 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(); } ,这样可以节省您添加每个边缘情况。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。