Discord.js“类型错误:无法读取未定义的属性‘发送’”

时间:2021-01-08 15:48:10

标签: node.js discord.js

所以我想提供更多关于我正在做的事情的细节以使其更容易理解:我正在使用 Discord.js V12 制作一个虚拟食品配送机器人,有一个订单命令和一个订单来声明订单和另一个交付订单的命令,问题发生在使用交付命令时,似乎问题也与其他命令有关,但我不确定在使用“交付”命令时出现此错误“类型错误:无法读取未定义的属性“发送”” 主要给出错误的行是这样的:

 client.channels.cache.get(order.channelID).send(`${client.users.cache.get(order.userID)}, Here is your taco that you ordered. Remember you can do \`.tip [Amount]\` to give us virtual tips, and \`.feedback [Feedback]\` to give us feedback on how we did. ${args[2]}`);

该行来自“delivery”命令,其完整代码在这里:

const { prefix } = require('../config.json');
const Discord = require('discord.js');
const fsn = require("fs-nextra");
const client = new Discord.Client();
const colors = require("colors");
module.exports = {
    name: 'deliver',
    description: 'Deliverying an order',
    args: 'true',
    usage: '<order ID> <imageURL>',
    aliases: ['d'],
    execute(message) {
        
        
        const args = message.content.slice(prefix.length).trim().split(/ +/g);
        
        if (message.member.roles.cache.find(r => r.id === '745410836901789749')) {
            if(message.guild.channels.cache.find(r => r.id === '746423099871985755')) {
                fsn.readJSON("./orders.json").then((orderDB) => {
                    let ticketID = args[1];
                    let imageURL = args[2];
                    let order = orderDB[ticketID];

                    // If the order doesn't exist.
                    if(order === undefined) {
                        message.reply(`Couldn't find order \`${args[1]}\` Try again.`);

                        return;
                    }
                    
                    if(imageURL === undefined) {
                        message.reply('Correct usage: \`.deliver (order ID) (ImageURL)\`');

                        return;
                    }
                    client.channels.cache.get(order.channelID).send(`${client.users.cache.get(order.userID)}, Here is your taco that you ordered. Remember you can do \`.tip [Amount]\` to give us virtual tips, and \`.feedback [Feedback]\` to give us feedback on how we did. ${args[2]}`);
                    // Checks status.
                    if (order.status === "Ready") {
                        // Delete ticket from database.
                        delete orderDB[ticketID];

                        // Writes data to JSON.
                        fsn.writeJSON("./orders.json", orderDB, {
                            replacer: null,
                            spaces: 4
                        }).then(() => {
                            message.reply(`Order \`${args[1]}\` Has been sent.`)
                            

                            console.log(`Order ${args[1]} has been sent.`)
                
            
                            
                        }).catch((err) => {
                            if (err) {
                                message.reply(`There was an error while writing to the database! Show the following message to a developer: \`\`\`${err}\`\`\``);
                            }
                        });
                    }else if(order.status === "Unclaimed") {
                        message.reply("This order hasn't been claimed yet. Run `.claim [Ticket ID]` to claim it.");
                    }else if(order.status === "Claimed") {
                        if(message.author.id === order.chef) {
                            message.reply("You haven't set an image for this order! yet Use `.setorder [Order ID]` to do it.");
                        }else {
                            message.reply(`This order hasn't been set an image yet, and only the chef of the order, ${client.users.get(order.chef).username} may set this order.`);
                        }
                    }else if(order.status === "Waiting") {
                        message.reply("This order is in the waiting process right now. Wait a little bit, then run `.deliver [Order ID] to deliver.");
                    }
                });
            }else {
                message.reply("Please use this command in the correct channel.");
                console.log(colors.red(`${message.author.username} used the claim command in the wrong channel.`));
            }
        }else {
            message.reply("You do not have access to this command.");
            console.log(colors.red(`${message.author.username} did not have access to the deliver command.`));
        }
    }
}

该命令从“orders.json”文件中获取信息,该文件存储这样的订单

{
    "VLC": {
        "orderID": "VLC",
        "userID": "734532125021307001",
        "guildID": "745409671430668389",
        "channelID": "746423099871985755",
        "order": "a",
        "status": "Ready",
        "ticketChannelMessageID": "not set",
        "chef": "734532125021307001"
    }
}

抱歉包含了这么多细节,但这个错误阻止了我的所有机器人执行其主要功能 如果包含“订单”和“索赔”命令的代码有帮助,请告诉我并编辑帖子

编辑:我在代码的开头添加了 console.log(order.channelID)console.log(order.userID),它实际上为这些记录了正确的 ID,那么为什么它不希望它向那里发送消息?

1 个答案:

答案 0 :(得分:0)

我刚换了

client.channels.cache.get(order.channelID).send(`${client.users.cache.get(order.userID)}, Here is your taco that you ordered. Remember you can do \`.tip [Amount]\` to give us virtual tips, and \`.feedback [Feedback]\` to give us feedback on how we did. ${args[2]}`);

const customerchannel = message.guild.channels.cache.find(c => c.id === order.channelID)
                    customerchannel.send(`<@${order.userID}>, Here is your taco that you ordered. Remember you can do \`.tip [Amount]\` to give us virtual tips, and \`.feedback [Feedback]\` to give us feedback on how we did. ${args[2]}`);

它的工作非常愚蠢