npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-money-mongoose

v3.0.3

Published

Money system for discordjs using mongoose

Downloads

33

Readme

discord-money-mongoose

npm NPM npm

Money manager for discord.js bots

Updates!

  • 2.0.0, Updated to discord.js version v12
  • 3.0.0, Rewriten in Typescript .Now should be faster and more compatible, now it has more tools built into it

Important!

This module requires discord.js and mongoose preinstalled

Features!

  • Fetch multiple users
  • Leaderboard ready auto sort dmm.getLeaderboard()
  • get formated RichEmbed Leaderboard for simple use
  • Set user's money
  • Increase money of a user
  • Decrease money of a user
  • Delete user document
  • Delete multiple user documents
  • Use custom fields for money
  • Custom name for collection
  • Can put custom query resolver
  • Provide a custom model with custom resolver

to-do:

  • Suggest what to add next at github

Guides

Installation

$ npm install discord-money-mongoose

Example

  • Here's a example of using this module
const DiscordMoneyMongoose = require('discord-money-mongoose');
const { Client } = require('discord.js');
const { connect } = require('mongoose');

async function init() {

    await connect('MONGO URI', {
        useNewUrlParser: true,
        useUnifiedTopology: true
    });

    const bot = new Client({ disableEveryone: true });

    const money = new DiscordMoneyMongoose();

    bot.on('message', async msg => {
        if (msg.author.bot || !msg.content.startsWith('!')) return;
        if (msg.channel.type === "dm") return;
        const [command, ...args] = msg.content
            .slice('!'.length)
            .split(' ');

        switch (command.toLowerCase()) {
            case "money":
                msg.channel.send(`Money: ${await money.getMoney(msg.member)}`);
                break;
            case "increase":
                await money.increaseMoney(msg.member, args[0])
                msg.channel.send(`Increased by ${args[0]}`);
                break;
            case "decrease":
                money.decreaseMoney(msg.member, args[0]);
                msg.channel.send(`Decreased by ${args[0]}`);
                break;
            case "set":
                money.setMoney(msg.member, args[0]);
                msg.channel.send(`Set to ${args[0]}`);
                break;
            case "usermoney":
                msg.channel.send(`${msg.mentions.members.first()} has ${await money.getMoney(msg.mentions.members.first())} `);
                break;
            case "setusermoney":
                money.setMoney(msg.mentions.members.first(), args[1]);
                msg.channel.send(`Set ${msg.mentions.members.first()} 's money to ${args[1]}`);
                break;
            case "leaderboard":
                msg.channel.send(await money.formatLeaderboard(msg.guild));
                break;
        }
    });

    bot.login('BOT TOKEN');
}

init();

Syntax

Main

const DiscordMoneyMongoose = require('discord-money-mongoose');
const _DiscordMoneyMongoose = new DiscordMoneyMongoose(options); 

Options

Parameters|info -|- modeName| Custom collection name additionalSchema|Add aditional values to the default schema customModel|Set to use a custom model

Options.customModel

  • Defaults to money field if nothing is provided

Parameters|info|required -|-|- model|Custom model to use|Yes query|Custom query filter for finding the user|Recommended multipleQuery|Query for finding multiple members|No customGuildIdQuery|Query for finding members inside guild| Needed for leaderboard

interface {
    modelName?: string;
    additionalSchema?: SchemaDefinition;
    customModel?: {
        query?: (member: GuildMember) => MongooseFilterQuery<Pick<Document, "_id">>;
        model: Model<Document, {}>;
        multipleQuery?: (members: GuildMember[]) => MongooseFilterQuery<Pick<Document, "_id">>;
        customGuildIdQuery?: (guildID: string) => MongooseFilterQuery<Pick<Document, "_id">>;
    }
}

async getData(member: GuildMember)

  • Use await when calling function

| Parameters | First | |------------|-----------------| | Input | GuildMember | | Type | GuildMember |

| Returns | Type | |----------------------|--------| | Members collection document | Promise<Document | null> |

async getRawData(member: GuildMember)

  • Use await when calling function

| Parameters | First | |------------|-----------------| | Input |GuildMember | | Type | GuildMember |

| Returns | Type | |----------------------|--------| | Members collection document | Promise<Pick<Document, "_id"> | null> |

async getCustomField(member: GuildMember, field: string)

  • Use await when calling function

| Parameters | First |Second| |------------|-----------------|-| | Input | GuildMember |Custom field| | Type | GuildMember |String|

| Returns | Type | |----------------------|--------| | Members collection document | Promise<Promise<any | null>> |

async getMoney(member: GuildMember, customField?: string)

  • Use await when calling function

| Parameters | First |Second| |------------|-----------------|-| | Input | GuildMember |Custom field| | Type | GuildMember |String|

| Returns | Type | |----------------------|--------| | User's current money | Promise |

async deleteMoney(member: GuildMember)

  • Use await when calling function

| Parameters | First | |------------|-----------------| | Input | GuildMember | | Type | GuildMember |

async deleteMany(member: GuildMember)

  • Use await when calling function

| Parameters | First | |------------|-----------------| | Input | Array of GuildMember | | Type | GuildMember[] |

async increaseMoney(member: GuildMember, increase: number, customField?: string)

| Parameters | First | Second |Third| |------------|-----------------|---------------------------------|-| | Input | GuildMember | The amount of money to increase |Custom field| | Type | GuildMember | Number |string|

async decreaseMoney(member: GuildMember, decrease: number, customField?: string)

| Parameters | First | Second |Third| |------------|-----------------|---------------------------------|-| | Input | A GuildMember | The amount of money to decrease |Custom field| | Type | GuildMember | Number |string|

async setMoney(GuildMember, increase)

| Parameters | First | Second |Third| |------------|-----------------|--------------------------------|-| | Input | A GuildMember | The amount to set user's money |Custom field| | Type | GuildMember | Number |string|

async increaseMultiple(members: GuildMember[], increase: number, customField?: string)

| Parameters | First| Second| Third -|-|-|- | Input| An array of GuildMembers | The amount of money to increase for users | Custom field | | Type | Array | Number | string |

async decreaseMultiple(members: GuildMember[], decrease: number, customField?: string)

| Parameters | First| Second| Third -|-|-|- | Input| An array of GuildMembers | The amount of money to decrease for users | Custom field | | Type | Array | Number | string |

async setMultiple(members: GuildMember[], amount: number, customField?: string)

| Parameters | First| Second| Third -|-|-|- | Input| An array of GuildMembers | The amount of money to set for users | Custom field | | Type | Array | Number | string |

async getMultiple(members)

| Parameters | First | |------------|----------------------------| | Input | An array of GuildMembers | | Type | Array |

|Returns|Type| -|- |Array of member documents|Array

async getRawMultiple(members)

| Parameters | First | |------------|----------------------------| | Input | An array of GuildMembers | | Type | Array |

|Returns|Type| -|- |Array of member documents|Array<Document<Pick<"_id", {}>>>

async getLeaderboard(guild: Guild, limit: number, options?: { customField?: string, useFetch?: boolean })

| Parameters | First |Second|Third |------------|-----------------|-|- | Input | Input a Guild |Max number of users returned|Options | Type | Guild |number|Object

Options

Parameters|Custom field|Use Fetch -|-|- Input|Custom field|Use fetch functionallity in discord.js Type|string|boolean

| Returns | Type | |------------------------------------------------------------------------------------------------------------|-------| | Array of members and money | Array<{ member: GuildMember, money: number }> |

async formatLeaderboard(guild: Guild, options?: { customField?: string, color?: ColorResolvable, pageSize?: number, page?: number, title?: string })

| Parameters | First | Second | |------------|-----------------|---------| | Input | Input a Guild | Options | | Type | Guild | Object |

| Options | customField | pageSize | title | |---------|----------------------------|--------------------|--------------------| | Input | Custom field | Max members | Title of the embed | | Type |string|number|

| Returns | Type | |-------------------------------------------------|-----------| | Returns a RichEmbed to be used in discord message | RichEmbed |

#How to?

Finishing it later time

License

This project is licensed under the MIT License