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

如何修復(fù):“TypeError:無法讀取未定義的屬性‘標(biāo)簽

How to fix: quot;TypeError: Cannot read property #39;tag#39; of undefinedquot; error in discord.js(如何修復(fù):“TypeError:無法讀取未定義的屬性‘標(biāo)簽’discord.js 中的錯誤)
本文介紹了如何修復(fù):“TypeError:無法讀取未定義的屬性‘標(biāo)簽’"discord.js 中的錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在制作一個 discord.js 機(jī)器人,并在其中放入了排行榜命令.

I'm making a discord.js bot and I've put a leaderboard command in it.

    const Discord = require("discord.js");
  // Get a filtered list (for this guild only), and convert to an array while we're at it.
  const filtered = client.points.filter( p => p.guild === message.guild.id ).array();

  // Sort it to get the top results... well... at the top. Y'know.
  const sorted = filtered.sort((a, b) => b.points - a.points);

  // Slice it, dice it, get the top 10 of it!
  const top10 = sorted.splice(0, 10);

  // Now shake it and show it! (as a nice embed, too!)
  const embed = new Discord.RichEmbed()
    .setTitle("Leaderboard")
    .setAuthor(client.user.username, client.user.avatarURL)
    .setDescription("Our top 10 points leaders!")
    .setColor(0xff0000);
  for(const data of top10) {
    embed.addField(client.users.get(data.user).tag, `${data.points} points (level ${data.level})`);
  }
  return message.channel.send({embed});
}

但是當(dāng)我運(yùn)行命令時,我在命令行/日志中得到了這個:

But when I run the command I get this in the command line/logs:


    embed.addField(client.users.get(data.user).tag, `${data.points} points (level ${data.level})`);

                                              ^


TypeError: Cannot read property 'tag' of undefined

at Object.exports.run (/app/commands/leaderboard.js:19:47)

at module.exports (/app/events/message.js:19:7)

    at emitOne (events.js:121:20)

    at Client.emit (events.js:211:7)

    at MessageCreateHandler.handle (/rbd/pnpm-volume/461f582b-2c68-44a2-912c-88cd1fefb0fa/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)

    at WebSocketPacketManager.handle (/rbd/pnpm-volume/461f582b-2c68-44a2-912c-88cd1fefb0fa/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)

    at WebSocketConnection.onPacket (/rbd/pnpm-volume/461f582b-2c68-44a2-912c-88cd1fefb0fa/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)

    at WebSocketConnection.onMessage (/rbd/pnpm-volume/461f582b-2c68-44a2-912c-88cd1fefb0fa/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)

    at WebSocket.onMessage (/rbd/pnpm-volume/461f582b-2c68-44a2-912c-88cd1fefb0fa/node_modules/.registry.npmjs.org/ws/4.1.0/node_modules/ws/lib/event-target.js:120:16)

    at emitOne (events.js:116:13)

我已將機(jī)器人從我的電腦轉(zhuǎn)移到 glitch.com,這似乎修復(fù)了一段時間,但現(xiàn)在問題又回來了.

I've transferred the bot from my pc to glitch.com which seemed to fix it for a while, but now the problem is back.

推薦答案

這個錯誤意味著 client.users.get(data.user) 返回 undefined,因此不能有屬性 標(biāo)記就可以了.大概這意味著data中指定的用戶不存在.

The error means client.users.get(data.user) is returning undefined, hence there cannot be a property tag on it. Presumably this means the user specified in data does not exist.

您應(yīng)該在直接嘗試訪問該屬性之前添加一些防御性代碼,以確保 get() 調(diào)用返回一些內(nèi)容而不是 undefined.

You should add some defensive code before directly trying to access the property to ensure that the get() call returns something rather than undefined.

例如

const user = client.users.get(data.user);
if (user && user.tag) {
  // code here
} else {
  // user does not exist..
}

這篇關(guān)于如何修復(fù):“TypeError:無法讀取未定義的屬性‘標(biāo)簽’"discord.js 中的錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

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(如何讓我的機(jī)器人提及發(fā)出該機(jī)器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時的歡迎消息)
主站蜘蛛池模板: 亚洲一一在线 | 久久伊人青青草 | 国产成人久久av免费高清密臂 | 国产精品久久久久久亚洲调教 | 日韩精品一区二区三区中文字幕 | 亚洲第一视频网站 | 国产有码 | 伊人激情综合网 | 久久国产精品无码网站 | 中文字幕啪啪 | 欧洲精品一区 | 一区二区三区视频播放 | 久久久久久99| 在线国产一区二区 | 亚洲一区二区免费电影 | 青青草原综合久久大伊人精品 | 亚洲免费网 | 黄色片在线观看网址 | 男女网站免费观看 | 午夜影院污 | 在线播放亚洲 | 精久久久| 精品丝袜在线 | 高清黄色网址 | 天天视频成人 | 九九免费 | 日本三级精品 | 精品免费国产一区二区三区四区介绍 | 色综合国产| 国产精品美女久久久久 | 亚洲精品成人 | 看黄在线 | 国产精品亚洲成在人线 | 国产网站在线免费观看 | 99久久久久久99国产精品免 | 欧美成年网站 | 偷拍自拍网址 | 亚州精品天堂中文字幕 | 9999国产精品欧美久久久久久 | 中文字幕一区二区三区在线观看 | 欧美一级黄色网 |