TypeError:无法读取未定义的属性'findOne'。僵尸机器人

时间:2019-04-21 10:50:52

标签: mongodb discord.js commando

我一直在尝试建立货币系统,但是当尝试使用Money.findOne时,它只会输出

  

TypeError:无法读取未定义的属性'findOne'

我将其从每次调用该命令的运行代码更改为一次,因为这会输出错误

const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/bot', {useNewUrlParser: true});
var Schema = new mongoose.Schema({
  userid: String,
  serverid: String,
  balance: Number,
});

var {Money} = mongoose.model("balances", Schema);

module.exports = class balance extends Command {
  constructor(client) {
    super(client, {
      name: 'balance',
      group: 'gambling',
      memberName: 'balance',
      description: 'Shows your balance.',
      clientPermissions: ['MANAGE_CHANNELS'],
      examples: ['balance'],
    });
  }

  run(message){
    var uid = message.author.id;
    var sid = message.guild.id;

    Money.findOne({ userid: uid, serverid: sid }, function (err, adventure) {
      if(err) console.log(err);
      if(!balance){
        var input = new Money({
          userid: uid,
          serverid: sid,
          balance: 1000,
        });

        input.save(function (err, input) {
          if (err) return console.error(err);
        });

        const Embed = new RichEmbed()
         .setColor('#3c82f2')
         .setTitle('Balance')
         .setThumbnail(message.author.avatarURL)
         .addField('Your balance is: ', '1000')
         .setTimestamp()
         message.channel.send(Embed);
      }else if(balance){
        const Embed = new RichEmbed()
          .setColor('#3c82f2')
          .setTitle('Balance')
          .setThumbnail(message.author.avatarURL)
          .addField('Your balance is: ', balance.balance)
          .setTimestamp()

        message.channel.send(Embed);
      }
    });
  }
}

它正在输出一个显示您的余额的嵌入

0 个答案:

没有答案