简体   繁体   English

方法不返回整个 object

[英]Method does not return whole object

When I call the method buildCommand, it does not return the property message, but I found out that if I remove some properties out of buildCommand, it works.当我调用 buildCommand 方法时,它不会返回属性消息,但我发现如果我从 buildCommand 中删除一些属性,它就可以工作。 This is the method I call这是我调用的方法

const buildCommand = (commandJSON) => {
        return new Command({
        prefix: commandJSON.prefix,
        command: commandJSON.command,
        aliases: commandJSON.aliases,
        parameters: commandJSON.parameters,
        message: commandJSON.message,
        response: commandJSON.response,
        commandMedium: commandJSON.commandMedium,
        enabled: commandJSON.enabled,
        isDefault: commandJSON.isDefault,
        permission: commandJSON.permission,
        cooldown: commandJSON.cooldown,
      });
    };

This is how I call the method这就是我调用该方法的方式

const newCommand = buildCommand(commandJSON);

commandJSON looks like this commandJSON 看起来像这样

{ prefix: '!', command: 'laugh', message: 'hahaha' }

UPDATE 2 Here is my whole Command Model更新 2 这是我的整个命令 Model

const mongoose = require('mongoose');

const commandSchema = mongoose.Schema({
  prefix: {
    type: String,
    default: '!',
  },
  command: {
    type: String,
    required: true,
  },
  aliases: {
    type: Array,
  },
  parameters: {
    type: Array,
  },
  message: {
    type: String,
  },
  response: {
    type: String,
    enum: ['chat', 'whisper'],
    default: 'chat',
  },
  commandMedium: {
    type: String,
    enum: ['offline', 'online', 'both'],
    default: 'both',
  },
  enabled: {
    type: Boolean,
    default: true,
  },
  isDefault: {
    type: Boolean,
    default: false,
  },
  permission: {
    type: String,
    enum: ['everyone', 'subscriber', 'vip', 'moderator', 'broadcaster'],
    default: 'everyone',
  },
  cooldown: {
    globalCooldown:{type:Boolean, default:false},
    globalDuration:{type:Number, default:0},
    userDuration:{type:Number,default:0},
  }
});

module.exports = mongoose.model('Commands', commandSchema, 'TwitchUsers');

Command is just a Mongoose model.命令只是一个 Mongoose model。 There's nothing async in there, you can (and should) remove the async/await stuff.那里没有任何异步,您可以(并且应该)删除async/await的东西。

You can simply do const newCommand = new Command(commandJSON) , job done.您可以简单地执行const newCommand = new Command(commandJSON) ,完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM