【问题标题】:Cannot read property 'channels' of undefined | discordjs无法读取未定义的属性“通道”|不和谐
【发布时间】:2020-11-02 01:11:59
【问题描述】:

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

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.

【问题讨论】:

    标签: discord.js


    【解决方案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}`
            ); 
        }
    

    【讨论】:

      猜你喜欢
      • 2021-10-03
      • 2020-05-22
      • 1970-01-01
      • 2022-01-06
      • 2020-11-28
      • 2021-03-31
      • 2020-11-10
      • 2020-11-11
      相关资源
      最近更新 更多