因此,我試圖編寫(xiě)一個(gè)在Facebook上發(fā)布的機(jī)器人,“您不會(huì)(隨機(jī)動(dòng)詞)是一個(gè)(隨機(jī)名詞),對(duì)嗎?” 每隔一小時(shí)。我有一長(zhǎng)串動(dòng)詞和名詞,分別為“ verbs.txt”和“ nouns.txt”。我遇到的麻煩是讓程序讀取文件,從文件中選擇一個(gè)隨機(jī)單詞并將其存儲(chǔ)在變量中。我嘗試了很多不同的事情,但沒(méi)有結(jié)果,我將代碼運(yùn)行回該版本,除了未定義的變量。let postContents = "You wouldn't" + verb + " a " + noun + ", would you?";FB.api('me/feed', 'post', { message: postContents }, res => { if (!res || res.error) { return console.error(!res ? 'error occurred' : res.error); } console.log(`Post ID: ${res.id}`);});
如何使用node.js讀取名詞的文本文件并將其存儲(chǔ)在變量中
哈士奇WWW
2021-04-08 10:11:53