UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ id”

帕辛杜·拉纳辛格(Pasindu Ranasinghe)

我一直在尝试制作一个简单的机器人列表,我想从数据库中获取提到的机器人信息。该数据库包含机器人ID。您可以在下面找到我的代码。

获取机器人信息的代码。

const Discord = require('discord.js');
const Botinfo = require('../models/bot.js');

module.exports = {
        name: 'botinfo',
        description: 'Send all the information about the bot in database',

        async execute(client, message, args) {

                const botmention = message.mentions.users.first();
                const mentionid = message.mentions.users.first().id()
                if (!botmention) {
                        const embed = new Discord.MessageEmbed()
                                .setTitle('Error :)')
                                .setColor('RED')
                                .setDescription('You must mention the bot that want information')
                                .setFooter(`By ${message.author.tag}`)
                                .setTimestamp()
                        message.channel.send(embed)
                        return;
                }
                const bot = await Botinfo.findOne({ botid: mentionid })
                if (!bot) {
                        const embed1 = new Discord.MessageEmbed()
                                .setTitle('Error :)')
                                .setColor('RED')
                                .setDescription('We can\'t find that bot in our database, Sorry about that')
                                .setFooter(`By ${message.author.tag}`)
                                .setTimestamp()

                        message.channel.send(embed1)
                        return;
                }
                const embed2 = new Discord.MessageEmbed()
                        .setTitle('Bot Information You asked')
                        .setColor('GREEN')
                        .setDescription('These information have directly got from our database')
                        .addField('Botname:', `<@${id}>`)
                        .addField('Bot ID:', `${id}`)
                        .addField('Bot Prefix:', bot.botprefix)
                        .addField('Bot Image URL:', bot.botimage)
                        .addField('Bot Status:', bot.state)
                        .addField('Certification Status:', bot.certification)
                        .addField('Bot Owner:', `<@${bot.botowner}>`)
                        .setFooter(`Requested By ${message.author.tag}`)
                        .setTimestamp()

                message.channel.send(embed2)
        }
}

当我执行此命令时。我得到这个错误。

(node:15072) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of undefined
    at Object.execute (C:\Users\user\Desktop\BotWorld\commands\botinfo.js:11:65)
    at Client.<anonymous> (C:\Users\user\Desktop\BotWorld\index.js:40:46)
    at Client.emit (events.js:314:20)
    at MessageCreateAction.handle (C:\Users\user\Desktop\BotWorld\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\user\Desktop\BotWorld\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)    at WebSocketManager.handlePacket (C:\Users\user\Desktop\BotWorld\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\user\Desktop\BotWorld\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\user\Desktop\BotWorld\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\user\Desktop\BotWorld\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:314:20)
    at Receiver.receiverOnMessage (C:\Users\user\Desktop\BotWorld\node_modules\ws\lib\websocket.js:825:20)
    at Receiver.emit (events.js:314:20)
    at Receiver.dataMessage (C:\Users\user\Desktop\BotWorld\node_modules\ws\lib\receiver.js:437:14)
    at Receiver.getData (C:\Users\user\Desktop\BotWorld\node_modules\ws\lib\receiver.js:367:17)
    at Receiver.startLoop (C:\Users\user\Desktop\BotWorld\node_modules\ws\lib\receiver.js:143:22)
    at Receiver._write (C:\Users\user\Desktop\BotWorld\node_modules\ws\lib\receiver.js:78:10)
(node:15072) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15072) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate 
the Node.js process with a non-zero exit code.

任何帮助将不胜感激。

德米特29

第11行:.id而不是.id(),id是一个属性,而不是一个方法

const mentionid = message.mentions.users.first().id

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ id”

来自分类Dev

UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ public_id”

来自分类Dev

Gatsby TypeError-无法读取未定义的属性“ id”

来自分类Dev

MERN-TypeError:无法读取未定义的属性“ id”

来自分类Dev

Angular Material TypeError:无法读取未定义的属性“ id”

来自分类Dev

JWT-TypeError:无法读取未定义的属性“id”

来自分类Dev

无法读取未定义的属性“ id”

来自分类Dev

Angular2-TypeError:无法读取(Typescript)中未定义的属性'Id'

来自分类Dev

AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性'__id'

来自分类Dev

TypeError:无法读取未定义的属性'id'-Sails和MongoDB

来自分类Dev

未捕获的TypeError:无法读取registerNgModuleType上未定义的属性“ id”-角度PWA

来自分类Dev

NodeJs TypeError:无法读取未定义的属性“ Customer_id”

来自分类Dev

core.js:6406错误TypeError:无法读取未定义的属性“ id”

来自分类Dev

TypeError:无法读取未定义的属性“ id” Discord.js

来自分类Dev

错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ id”

来自分类Dev

错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ id”

来自分类Dev

core.js:30235未捕获的TypeError:无法读取未定义的属性'id'

来自分类Dev

AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性“ __id”

来自分类Dev

未捕获的TypeError:无法读取未定义的属性'company_id'

来自分类Dev

MongoError:TypeError:使用$ or时,无法读取未定义的属性“ id”

来自分类Dev

灰烬路线:无法读取未定义的属性“ id”

来自分类Dev

guildBanAdd无法读取未定义的属性“ id”

来自分类Dev

删除时出错:无法读取未定义的属性“ id”

来自分类Dev

Serverless:“ errorMessage”:“无法读取未定义的属性” id“,

来自分类Dev

用户注销后无法读取未定义的属性“ _id”

来自分类Dev

guildBanAdd无法读取未定义的属性“ id”

来自分类Dev

无法读取未定义的属性“ id”。表示

来自分类Dev

错误TypeError:无法在tipo-struttura.component.ts(angular + spring + sql)读取未定义的属性'id'

来自分类Dev

在 javascript Uncaught TypeError 中使用数组的动态循环时,for 循环中的问题:无法在 saveSign 读取未定义的属性“id”

Related 相关文章

  1. 1

    UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ id”

  2. 2

    UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ public_id”

  3. 3

    Gatsby TypeError-无法读取未定义的属性“ id”

  4. 4

    MERN-TypeError:无法读取未定义的属性“ id”

  5. 5

    Angular Material TypeError:无法读取未定义的属性“ id”

  6. 6

    JWT-TypeError:无法读取未定义的属性“id”

  7. 7

    无法读取未定义的属性“ id”

  8. 8

    Angular2-TypeError:无法读取(Typescript)中未定义的属性'Id'

  9. 9

    AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性'__id'

  10. 10

    TypeError:无法读取未定义的属性'id'-Sails和MongoDB

  11. 11

    未捕获的TypeError:无法读取registerNgModuleType上未定义的属性“ id”-角度PWA

  12. 12

    NodeJs TypeError:无法读取未定义的属性“ Customer_id”

  13. 13

    core.js:6406错误TypeError:无法读取未定义的属性“ id”

  14. 14

    TypeError:无法读取未定义的属性“ id” Discord.js

  15. 15

    错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ id”

  16. 16

    错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ id”

  17. 17

    core.js:30235未捕获的TypeError:无法读取未定义的属性'id'

  18. 18

    AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性“ __id”

  19. 19

    未捕获的TypeError:无法读取未定义的属性'company_id'

  20. 20

    MongoError:TypeError:使用$ or时,无法读取未定义的属性“ id”

  21. 21

    灰烬路线:无法读取未定义的属性“ id”

  22. 22

    guildBanAdd无法读取未定义的属性“ id”

  23. 23

    删除时出错:无法读取未定义的属性“ id”

  24. 24

    Serverless:“ errorMessage”:“无法读取未定义的属性” id“,

  25. 25

    用户注销后无法读取未定义的属性“ _id”

  26. 26

    guildBanAdd无法读取未定义的属性“ id”

  27. 27

    无法读取未定义的属性“ id”。表示

  28. 28

    错误TypeError:无法在tipo-struttura.component.ts(angular + spring + sql)读取未定义的属性'id'

  29. 29

    在 javascript Uncaught TypeError 中使用数组的动态循环时,for 循环中的问题:无法在 saveSign 读取未定义的属性“id”

热门标签

归档