pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

如何修復(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ù)器時的歡迎消息)
主站蜘蛛池模板: 飞扬动力官网-广告公司管理软件,广告公司管理系统,喷绘写真条幅制作管理软件,广告公司ERP系统 | 高铝轻质保温砖_刚玉莫来石砖厂家_轻质耐火砖价格 | 上海租车公司_上海包车_奔驰租赁_上海商务租车_上海谐焕租车 | 申江储气罐厂家,储气罐批发价格,储气罐规格-上海申江压力容器有限公司(厂) | 上海深蓝_缠绕机_缠膜机-上海深蓝机械装备有限公司 | 成都软件开发_OA|ERP|CRM|管理系统定制开发_成都码邻蜀科技 | 防爆正压柜厂家_防爆配电箱_防爆控制箱_防爆空调_-盛通防爆 | 钢化玻璃膜|手机钢化膜|钢化膜厂家|手机保护膜-【东莞市大象电子科技有限公司】 | 合肥白癜风医院_[治疗白癜风]哪家好_合肥北大白癜风医院 | 北京发电机出租_发电机租赁_北京发电机维修 - 河北腾伦发电机出租 | 地埋式垃圾站厂家【佳星环保】小区压缩垃圾中转站转运站 | 【官网】博莱特空压机,永磁变频空压机,螺杆空压机-欧能优 | 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 浩方智通 - 防关联浏览器 - 跨境电商浏览器 - 云雀浏览器 | 反渗透水处理设备|工业零排放|水厂设备|软化水设备|海南净水设备--海南水处理设备厂家 | 棉柔巾代加工_洗脸巾oem_一次性毛巾_浴巾生产厂家-杭州禾壹卫品科技有限公司 | 重庆磨床过滤机,重庆纸带过滤机,机床伸缩钣金,重庆机床钣金护罩-重庆达鸿兴精密机械制造有限公司 | 烽火安全网_加密软件、神盾软件官网| 山东PE给水管厂家,山东双壁波纹管,山东钢带增强波纹管,山东PE穿线管,山东PE农田灌溉管,山东MPP电力保护套管-山东德诺塑业有限公司 | MES系统工业智能终端_生产管理看板/安灯/ESOP/静电监控_讯鹏科技 | 移动机器人产业联盟官网| 镀锌方管,无缝方管,伸缩套管,方矩管_山东重鑫致胜金属制品有限公司 | 防爆正压柜厂家_防爆配电箱_防爆控制箱_防爆空调_-盛通防爆 | 手术室净化厂家_成都实验室装修公司_无尘车间施工单位_洁净室工程建设团队-四川华锐16年行业经验 | 脱硫搅拌器厂家-淄博友胜不锈钢搅拌器厂家 | 北京发电机出租_发电机租赁_北京发电机维修 - 河北腾伦发电机出租 | 宁夏活性炭_防护活性炭_催化剂载体炭-宁夏恒辉活性炭有限公司 | 中式装修设计_全屋定制家具_实木仿古门窗花格厂家-喜迎门 | 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 稳尚教育加盟-打造高考志愿填报平台_新高考志愿填报加盟_学业生涯规划加盟 | 上海橡胶接头_弹簧减震器_金属软接头厂家-上海淞江集团 | 回转支承-转盘轴承-回转驱动生产厂家-洛阳隆达轴承有限公司 | 实验室pH计|电导率仪|溶解氧测定仪|离子浓度计|多参数水质分析仪|pH电极-上海般特仪器有限公司 | 涿州网站建设_网站设计_网站制作_做网站_固安良言多米网络公司 | 超声波分散机-均质机-萃取仪-超声波涂料分散设备-杭州精浩 | 诚暄电子公司首页-线路板打样,pcb线路板打样加工制作厂家 | sus630/303cu不锈钢棒,440C/430F/17-4ph不锈钢研磨棒-江苏德镍金属科技有限公司 | 温州在线网| 游动电流仪-流通式浊度分析仪-杰普仪器(上海)有限公司 | 金属回收_废铜废铁回收_边角料回收_废不锈钢回收_废旧电缆线回收-广东益夫金属回收公司 | 小型铜米机-干式铜米机-杂线全自动铜米机-河南鑫世昌机械制造有限公司 |