【问题标题】:(node:24) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null(节点:24)UnhandledPromiseRejectionWarning:TypeError:无法读取属性'send' of null
【发布时间】:2020-12-04 21:31:51
【问题描述】:

错误:

   (node:24) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null
        at Client.<anonymous> (/home/container/index.js:49:16)
        at Client.emit (events.js:314:20)
        at Object.module.exports [as GUILD_CREATE] (/home/container/node_modules/discord.js/src/client/websocket/handlers/GUILD_CREATE.js:33:14)
        at WebSocketManager.handlePacket (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
        at WebSocketShard.onPacket (/home/container/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
        at WebSocketShard.onMessage (/home/container/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
        at WebSocket.onMessage (/home/container/node_modules/ws/lib/event-target.js:125:16)
        at WebSocket.emit (events.js:314:20)
        at Receiver.receiverOnMessage (/home/container/node_modules/ws/lib/websocket.js:797:20)
        at Receiver.emit (events.js:314:20)
    (node:24) 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:24) [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.

代码:

client.on("guildCreate", guild => {
   guild.owner.send("Thanks! You can use /help to discover commands. Don't forget to join our discord! https://discord.gg/EnR4PXK")
   client.channels.cache.get(`771736722894618685`).send(`PlayMusic zit nu ook in *${guild.name}* (${guild.id}), De eigenaar is: ${guild.owner.user.tag} (${guild.owner.user.id}) (<@${guild.owner.user.id}>) . Deze server heeft *${guild.memberCount}* leden! :tada: ** De bot zit nu in ${client.guilds.cache.size} servers** `)
   console.log(`PlayMusic zit nu ook in ${guild.name} (${guild.id}), De eigenaar is: ${guild.owner.user.username} (${guild.owner.user.id}). Deze server heeft ${guild.memberCount} leden!`);
   channel.createInvite({unique: true})
});

首先他工作了一个月,然后我得到了这个错误?有人知道创建这样的东西的正确方法吗?

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    Guild#owner 是一个可以为空的属性,它依赖于缓存。通过GuildMemberManager#fetch() 获取所有者,使用Guild#ownerID强制缓存用户对象。

    // make sure to make your function async!
    const owner = await client.users.fetch(guild.ownerID);
    owner.send(...);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-10
      • 2021-03-27
      • 2021-09-16
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 2020-08-18
      • 2020-12-11
      相关资源
      最近更新 更多