Home > Software engineering >  How to make register command on discord.js and mongodb atlas?
How to make register command on discord.js and mongodb atlas?

Time:06-11

I want to save my discord member data using register command, please help me!!

bot.js

 client.on("message", msg => {
  if (msg.content === "!register, ign:<input from member>, level:<input from member>"){
    const newProfileSchema = new ProfileSchema({
      discordid: "Discord Member Username",
      ign: "<input from member>",
      level: "<input from member>",
    })
  }
})

And this is the schema look like Schema.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ProfileSchema = new Schema({
  discordid: {
    type: String,
    required: true
  },
  ign: {
    type: String
  },
  level: {
    type: Number
  }
});

module.exports = User = mongoose.model('profile', ProfileSchema);

CodePudding user response:

From what I understood, because your question is not clear at all You need to add collection to your db using mongoose when command !register is run.

const ign = args.slice(1).join(" ")
const level = args.slice.... // same thing 
const newSchemaprofile = new Schema({
       discordid: message.author.id,
       ign: ign,
       level: level,
}).save();
message.reply({content: 'Your data is saved'})

This is how you save data with mongoose

  • Related