【问题标题】:discord.js - TypeError: Cannot read property 'cache' of undefined Errordiscord.js - TypeError:无法读取未定义错误的属性“缓存”
【发布时间】:2021-04-19 15:05:06
【问题描述】:

使用我的命令将消息发送到另一台服务器时,我收到错误“TypeError: Cannot read property 'cache' of undefined”

fsn.readJSON("././orders.json").then((orderDB) => {
                    let ticketID = args[0];
                    
                    let order = orderDB[ticketID];
                    
                    
                    
                    // If the order doesn't exist.
                    if(order === undefined) {
                        message.reply(`Couldn't find order \`${args[0]}\` Try again.`);

                        return;
                    }
                    
                    if(!args[0]) {
                        message.reply('Correct usage: \`.deliver (order ID)\` Remember to have an attachment while using the command.');

                        return;
                    }

                    
                    
                    
                    if (message.author.id === order.chef) {
                        if (order.status === "Ready") {
                            if (message.attachments.size > 0) {
                                message.attachments.forEach(Attachment => {
                                    
                                    message.channels.cache.get(order.channelID).send(`Hi <@${order.userID}> I'm <@${order.chef}> and here is your taco that you ordered.  Remember you can use \`.feedback [Feedback]\` to give us feedback on how we did. ${Attachment.url}`);
                                })
                            } else {
                              return message.reply('Please attach an attachment while using the command.');
                            }
                            
                            delete orderDB[ticketID];

                            fsn.writeJSON("./orders.json", orderDB, {
                                replacer: null,
                                spaces: 4
                            }).then(() => {
                                message.reply(`Order \`${args[0]}\` Has been sent.`)
                                
    
                                console.log(`Order ${args[0]} has been delivered by ${order.chefmention}`)
                    
                
                                
                            }).catch((err) => {
                                if (err) {
                                    message.reply(`There was an error while writing to the database! Show the following message to a developer: \`\`\`${err}\`\`\``);
                                }
                            });
                        } else {
                            message.reply("This order hasn't been claimed yet. Run `.claim [Order ID]` to claim it.");
                        }
                    } else {
                        message.channel.send(`Only the chef of the order ${order.chefmention} may deliver this order`);
                    }
                
                   
                
                })

我猜是message.channels.cache.get(order.channelID).send(`Hi &lt;@${order.userID}&gt; I'm &lt;@${order.chef}&gt; and here is your taco that you ordered. Remember you can use \`.feedback [Feedback]\` to give us feedback on how we did. ${Attachment.url}`); 的错误,“order.channel.ID”存储在orders.json 文件中并且被定义我不知道代码有什么问题

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    Message 对象没有 channels 属性,您可能打算使用:

    message.client.channels.cache.get() //...
    

    【讨论】:

      猜你喜欢
      • 2021-02-27
      • 1970-01-01
      • 2020-07-23
      • 2020-10-01
      • 2021-03-15
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      相关资源
      最近更新 更多