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

时间:2020-08-08 06:27:56

标签: javascript node.js discord 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.

因此,我试图让DM命令仅由我(机器人的所有者)使用,因为我不希望人们滥用该命令并使我的机器人因其所做的事情而被禁止使用,但是这会导致此错误。我检查了discord.js.org,但找不到原因或解决方法。我检查了权限部分。请帮忙。谢谢。

1 个答案:

答案 0 :(得分:0)

代替if (!message.member.author.id === "356440200253276163")

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

message.member.author.id不是对象,这就是为什么它返回未定义的原因。

相关问题