第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何讓機(jī)器人回答用戶(hù),當(dāng)機(jī)器人響應(yīng)并且用戶(hù)想要繼續(xù)時(shí),就像對(duì)話(huà)一樣(但不重復(fù))

如何讓機(jī)器人回答用戶(hù),當(dāng)機(jī)器人響應(yīng)并且用戶(hù)想要繼續(xù)時(shí),就像對(duì)話(huà)一樣(但不重復(fù))

HUWWW 2022-12-18 16:20:23
例子:user: "Hello!" - bot: "Hi! You wanna help with the codes?"user: "No" - bot: "Okay!"但是只有當(dāng)用戶(hù)打招呼時(shí)才會(huì)發(fā)生。我不希望他回答“好吧!” 當(dāng)用戶(hù)在任何句子中說(shuō)“不”時(shí)......我用來(lái)回復(fù)用戶(hù)的機(jī)器人代碼是:client.on('message', async message => { if (message.content.toLowerCase().includes("hello")) {    message.channel.send("Hi! You wanna help with the codes?");}});對(duì)不起我的英語(yǔ)錯(cuò)誤,我不會(huì)說(shuō)那么多英語(yǔ)......無(wú)論如何,有人可以幫助我嗎?特別感謝:https ://stackoverflow.com/users/5896453/naszos
查看完整描述

1 回答

?
喵喔喔

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以為用戶(hù)定義一個(gè)狀態(tài),并根據(jù)用戶(hù)的回答決定下一步去哪里,例如(我假設(shè)客戶(hù)端對(duì)象上有某種 id):


const userStates = {};


const replies = {

  "": [

    {

      messages: ["hello"],

      answer: "Hi! You wanna help with the codes?",

      next_state: "asked_to_help",

    },

  ],

  asked_to_help: [

    {

      messages: ["no"],

      answer: "Okay :(",

      next_state: "",

    },

    {

      messages: ["yes"],

      answer: "Yay, tell me more!",

      next_state: "some_next_stage",

    },

  ],

};


client.on("message", async (message) => {

  userStates[client.id] = userStates[client.id] || "";

  const text = message.content.toLowerCase();

  const possibleReplies = replies[userStates[client.id]].filter((reply) =>

    reply.messages.includes(text)

  ); // filter by matching messages

  const reply = possibleReplies [Math.floor(Math.random() * possibleReplies .length)]; // get random answer from valid ones

  if (reply) {

    message.channel.send(reply.answer);

    userStates[client.id] = reply.next_state;

  } else {

    message.channel.send("I dont understand :(");

  }

});


查看完整回答
反對(duì) 回復(fù) 2022-12-18
  • 1 回答
  • 0 關(guān)注
  • 120 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)