简体   繁体   English

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

[英]TypeError: Cannot read property 'id' of undefined in Discord.js

module.exports = {
    name: "dm",
    description: "DM a user in the guild",
    category: "fun",
    run: async (bot, message, args) => {
      if (!member.message.author.id === ("356440200253276163"))
        return message.channel.send("**:x: You cannot use this command as it is only for the owner of bot. :x:**");
      let user =
        message.mentions.members.first() ||
        message.guild.members.cache.get(args[0]);
      if (!user)
        return message.channel.send(
         `**:x: You did not mention a user. :x:**`
        );
      if (!args.slice(1).join(" "))
        return message.channel.send("**:x: You did not specify your message. :x:**");
      user.user
        .send(args.slice(1).join(" "))
        .catch(() => message.channel.send("**:regional_indicator_x: That user could not be DMed! :regional_indicator_x:**"))
        .then(() => message.channel.send(`**:white_check_mark: Sent a message to ${user.user.tag} :white_check_mark:**`));
    },
  };
(node:4) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of undefined

2020-08-08T06:14:42.414100+00:00 app[worker.1]:     at Object.run (/app/commands/dm.js:33:34)

2020-08-08T06:14:42.414101+00:00 app[worker.1]:     at Client.<anonymous> (/app/bot.js:39:21)

2020-08-08T06:14:42.414101+00:00 app[worker.1]:     at Client.emit (events.js:327:22)

2020-08-08T06:14:42.414102+00:00 app[worker.1]:     at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)

2020-08-08T06:14:42.414103+00:00 app[worker.1]:     at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)

2020-08-08T06:14:42.414104+00:00 app[worker.1]:     at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)

2020-08-08T06:14:42.414104+00:00 app[worker.1]:     at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)

2020-08-08T06:14:42.414104+00:00 app[worker.1]:     at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)

2020-08-08T06:14:42.414105+00:00 app[worker.1]:     at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:125:16)

2020-08-08T06:14:42.414106+00:00 app[worker.1]:     at WebSocket.emit (events.js:315:20)

2020-08-08T06:14:42.414304+00:00 app[worker.1]: (node:4) 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)

2020-08-08T06:14:42.414353+00:00 app[worker.1]: (node:4) [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.

So I'm trying to make the DM command usable by only me, the owner of the bot because I don't want people to abuse it and get my bot banned for what they did, but it gives this error.所以我试图让 DM 命令只能由我,机器人的所有者使用,因为我不希望人们滥用它并让我的机器人因为他们所做的事情而被禁止,但它给出了这个错误。 I checked discord.js.org but I couldn't find why it happened or how to fix it.我检查了 discord.js.org 但我找不到它发生的原因或如何解决它。 I checked the permissions section.我检查了权限部分。 Please help.请帮忙。 Thank you.谢谢你。

Instead of if (.message.member.author.id === "356440200253276163") ,而不是if (.message.member.author.id === "356440200253276163")

use if (.message.author.id === "356440200253276163") .使用if (.message.author.id === "356440200253276163")

message.member.author.id is not an object, which is why it returns undefined. message.member.author.id不是 object,这就是它返回 undefined 的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM