javascript - 方法不返回整个对象
问题描述
当我调用 buildCommand 方法时,它不会返回属性消息,但我发现如果我从 buildCommand 中删除一些属性,它就可以工作。这是我调用的方法
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,
});
};
这就是我调用该方法的方式
const newCommand = buildCommand(commandJSON);
commandJSON 看起来像这样
{ prefix: '!', command: 'laugh', message: 'hahaha' }
更新 2 这是我的整个命令模型
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 只是一个 Mongoose 模型。那里没有任何异步内容,您可以(并且应该)删除这些async/await
东西。
你可以简单地做const newCommand = new Command(commandJSON)
,工作完成。
推荐阅读
- php - Laravel 中的多个条件子句过滤器
- c++ - 为什么 omp_set_num_threads( omp_get_num_threads() ) 会改变任何东西?
- javascript - 如何淡入和淡出多个元素?
- r - 为两个最高观察值创建指标?
- r - 在 geom_tile 不存在的地方添加零值
- python - 在python中使用双反斜杠而不是单个反斜杠获取当前工作目录
- python - 实施 os NMAE 作为 Keras 的度量
- css - React Native ScrollView 外容器样式 flex: value
- reactjs - 从模块模拟的 jest 函数在被其他方法调用时没有检测到它的调用
- amazon-web-services - 无法使用 Amazon Amplify 从 Lambda 调用 GraphQL