GithubHelp home page GithubHelp logo

discord.js-mongodb-economy's Introduction

Discord.js-MongoDb-Economy

Do you also want to create an economy system in discord.js v14? Well then this tutorial is for you.

First of all you need an command handler which supports mongoose. https://github.com/E1NZ1/Discord.js-SlashCommand-Handler This is the best handler so use it for best experience.

Getting Started

Ok so First let's create an schema

Create an folder models and make an file eco.js.

Then paste the following code there.

const mongoose = require("mongoose");

const eco = mongoose.Schema({
    userid: { type: String },
    cash: { type: Number, default: 100 }, // Default is optional.
})

module.exports = mongoose.model("eco", eco)

Useful Information (Required to Know)

Good. Now your main thing is ready here is a few functions to use in the commands

// we will define data in the code given late
data.cash += 100; // add some cash
data.cash -= 100; // remove cash
data.cash = 100: // set Cash
await data.save();

Creating Balamce Command

Ok so let's create an command


// Balance Command
const { EmbedBuilder } = require("discord.js")
const eco = require("../../models/eco");

module.exports = {
    name: "balance",
    description: "see your fazcash",
    options: [
        {
            name: "user",
            description: "user to view cash of",
            type: 6,
        },
    ],
    run: async (client, interaction) => {
        const user = interaction.options.getUser("user") || interaction.user;
        const data =
              (await eco.findOne({ userid: user.id })) ||
              (await eco.create({ userid: user.id }));
        
        await interaction.reply({
            embeds: [
                new EmbedBuilder()
               .setDescription(`${user.tag} currently has ${data.cash} cash`)
                .setColor("#303136")
                ],
        })
    }
}

Wonderful. Now try creating your own commands with the tips i gave

discord.js-mongodb-economy's People

Contributors

e1nz1 avatar

Stargazers

Mmmm avatar  avatar AnirudhSinh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.