久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 久久久久久久一区二区三区 | 欧美中文在线 | 在线观看国产 | 日日操操操 | 国产精品欧美一区喷水 | 亚洲一区免费视频 | 亚洲一区二区三区在线视频 | 国产清纯白嫩初高生视频在线观看 | 国产成在线观看免费视频 | 一级黄色片网站 | 国产精品av久久久久久久久久 | 91视频正在播放 | 久久在线视频 | 一区二区视频在线观看 | 国产一级一级国产 | 中文字幕精品一区久久久久 | 久久9久 | 国产欧美在线播放 | 成人免费毛片在线观看 | 久久亚洲欧美日韩精品专区 | 天天色影视综合 | 国产一区在线免费 | 日本a级大片 | 91xxx在线观看 | 国产小视频在线 | 国产中文字幕在线 | 欧美2区 | 日本特黄特色aaa大片免费 | 国产高清自拍视频在线观看 | av网站在线免费观看 | 国产精品免费一区二区三区四区 | 国产成人99久久亚洲综合精品 | 韩日在线视频 | 午夜精品一区二区三区在线视频 | 久久精品亚洲精品 | 亚洲在线视频 | 精品熟人一区二区三区四区 | 成人激情视频免费观看 | 国产精品久久久久久久久久妇女 | 欧美一区二区三区 | 日日操夜夜摸 |