That's because you have to initialize it before you can use it
You can set a default value on the schema
const mongoose = require('mongoose');
module.exports = mongoose.model(
'channels',
new mongoose.Schema({
channelID: {type: Array, default: []},
}),
);
In that way, it will always be an empty array.
Or you can check if it's empty and initialize it with an empty array before pushing
/* eslint-disable no-unused-vars */
const { MessageEmbed } = require('discord.js');
const config = require('../../utils/config.json');
const schema = require('../../models/channelSchema');
module.exports.run = async (client, message, args, utils) => {
const channel = message.mentions.channels.first();
if(!channel) return message.channel.send('please mention a channel.');
if(!schema.channelID) schema.channelID = [];
schema.channelID.push(channel.id);
message.channel.send(`chat set as <#${channel.id}>`);
};
Then, if it's not initialized, it will not appear in the database.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…