久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何獲取未緩存的數據?

How to fetch data which is not cached?(如何獲取未緩存的數據?)
本文介紹了如何獲取未緩存的數據?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

當我嘗試與數據交互時,會引發錯誤.

const user = client.users.cache.get(user.id);用戶.發送(消息);

<塊引用>

TypeError: 無法讀取未定義的屬性發送"

解決方案

緩存工具說明

緩存是一個Collection,是Collection的擴展Map 但帶有 array 方法等等.主要供managers使用,用來防止無用API 調用,當數據被獲取時,它也將被緩存,您將能夠在不發送 API 請求的情況下檢索它多少次.因此,當數據沒有被緩存時,這意味著數據還沒有被提取,你需要這樣做.

請求是對 Discord API 的調用,由 Discord.js 模塊,等待 Discord 服務器的響應,Promise 需要 awaited 帶有 await 關鍵字或 <Promise>.then 方法.

獲取示例

您可以獲取數據并將響應分配到變量中,當您想再次訪問它時,您將能夠在緩存中檢索數據.

/* 未獲取數據,因此尚未緩存 */console.log(client.users.cache.get(user.id));//不明確的/* 從 Discord 請求數據 */const fetchedData = 等待 client.users.fetch(user.id);console.log(fetchedData);//用戶 {}/* 數據已被獲取,因此您可以從緩存中檢索數據 */console.log(client.users.cache.get(user.id));//用戶 {}

經過這些解釋,出現此錯誤是正常的,因為無法將方法應用于undefined.

<塊引用>

TypeError: 無法讀取未定義的屬性 ''

When I try to interact with data an error is thrown.

const user = client.users.cache.get(user.id);
user.send(message);

TypeError: Cannot read property 'send' of undefined

解決方案

Explanation of cache utility

Cache is a Collection, an extend of Map but with array methods and more. It's mainly used by managers and used to prevents useless API calls, when data is fetched it will be cached too and you will be able to retrieve it how many time you want without sending API request. So when data is not cached it means that the data was not fetched yet and you'll need to.

A request is a call to the Discord API which is done by the Discord.js module, to wait the response of the Discord server, the Promise need to be awaited with await keyword or <Promise>.then method.

Fetch example

You can fetch data and assign the response in a variable, when you want to access it another time you will be able to retrieve data in the cache.

/* Data wasn't fetched so not cached yet */
console.log(client.users.cache.get(user.id)); // undefined

/* Request data from Discord */
const fetchedData = await client.users.fetch(user.id);
console.log(fetchedData); // User {}

/* Data has been fetched so you can retrieve data from cache */
console.log(client.users.cache.get(user.id)); // User {}

After these explanations, it's normal that this error appears since it's not possible to apply a method on something undefined.

TypeError: Cannot read property '' of undefined

這篇關于如何獲取未緩存的數據?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 六月成人网 | 日本电影免费完整观看 | 熟女毛片 | 亚洲成人黄色 | 国产亚洲精品91 | 国产精品视频免费观看 | 亚洲一区免费 | 成人免费视频一区二区 | 国产一区中文字幕 | 国产a级毛片 | 午夜天堂精品久久久久 | 国产精品福利在线 | 久久在线精品 | 欧美成人激情 | www.久| 日韩成人中文字幕 | 久久婷婷香蕉热狠狠综合 | 91色视频在线 | 欧美精品一区二区三区四区 在线 | 91一区二区三区在线观看 | 国产在线a | 91麻豆精品国产91久久久久久久久 | 在线国产一区 | 超碰男人天堂 | 精品久久久久久久久久久久久久久久久 | 国产做a爱片久久毛片 | 亚洲国产精品一区二区久久 | 午夜激情视频在线 | 亚洲 欧美 日韩 精品 | 天天爽天天干 | 午夜精品一区二区三区在线观看 | 18gay男同69亚洲网站 | 中文字幕免费观看 | 欧美一区2区三区4区公司二百 | 亚洲性爰| 中文字幕 在线观看 | 国产精品永久免费观看 | 成人二区三区 | 伊人网一区 | 成人在线免费观看 | 五月综合久久 |