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. 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
{ prefix: '!', command: 'laugh', message: 'hahaha' }
UPDATE 2 Here is my whole Command 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');
Advertisement
Answer
Command is just a Mongoose model. There’s nothing async in there, you can (and should) remove the async/await
stuff.
You can simply do const newCommand = new Command(commandJSON)
, job done.