无法读取未定义的属性“通道”不和谐

时间:2020-07-12 19:37:25

标签: discord.js

一旦反应被按下,机器人应在特定类别中创建新的文本聊天。但是这是代码:

bot.on("messageReactionAdd", async (reaction, user) => {
      if(user.bot) return;
      if (reaction.message.partial) await reaction.message.fetch();
      if (reaction.partial) await reaction.fetch();
      
      if (user.bot) return; // If the user was a bot, return.
      if (!reaction.message.guild) return; 
      if (reaction.message.guild.id !== "601109434197868574") return; 
  
      if (reaction.emoji.name === "?") {
        let channel = await reaction.guild.channels.create(`ticket-${user.username}-#${user.discriminator}`); 
#${user.discriminator}`); 
}})

然后出现以下错误:

(node:10948) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'channels' of undefined
    at Client.<anonymous> (C:\Users\eFhii\Desktop\Projects\Anastic\Bot\index.js:256:42)
    at Client.emit (events.js:215:7)
    at MessageReactionAdd.handle (C:\Users\eFhii\Desktop\Projects\Anastic\Bot\node_modules\discord.js\src\client\actions\MessageReactionAdd.js:44:17)
    at Object.module.exports [as MESSAGE_REACTION_ADD] (C:\Users\eFhii\Desktop\Projects\Anastic\Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_REACTION_ADD.js:4:37)
    at WebSocketManager.handlePacket (C:\Users\eFhii\Desktop\Projects\Anastic\Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (C:\Users\eFhii\Desktop\Projects\Anastic\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
    at WebSocketShard.onMessage (C:\Users\eFhii\Desktop\Projects\Anastic\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
    at WebSocket.onMessage (C:\Users\eFhii\Desktop\Projects\Anastic\Bot\node_modules\ws\lib\event-target.js:125:16)
    at WebSocket.emit (events.js:210:5)
    at Receiver.receiverOnMessage (C:\Users\eFhii\Desktop\Projects\Anastic\Bot\node_modules\ws\lib\websocket.js:797:20)
(node:10948) 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(). (rejection id: 1)
(node:10948) [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.

1 个答案:

答案 0 :(得分:1)

您有错字。更改

if (reaction.emoji.name === "?") {
        let channel = await reaction.guild.channels.create(`ticket-${user.username}-#${user.discriminator}`); 
#${user.discriminator}`); 
}

对此

    if (reaction.emoji.name === "?") {
        let channel = await reaction.message.guild.channels.create(
            `ticket-${user.username}-#${user.discriminator}`
        ); 
    }