Bank

Bank has now been separated from Economy for V3. New to bank is support for having a global bank.

Basic Usage

from core import bank

class MyCog:
    @commands.command()
    async def balance(self, ctx, user: discord.Member=None):
        if user is None:
            user = ctx.author
        bal = bank.get_balance(user)
        currency = bank.get_currency_name(ctx.guild)
        await ctx.send(
            "{}'s balance is {} {}".format(
                user.display_name, bal, currency
            )
        )

API Reference

Bank

The bank module.

class core.bank.Account

A single account. This class should ONLY be instantiated by the bank itself.

name

A string representing the name of the account

balance

An int representing the account’s balance

created_at

A datetime.datetime object representing the time the account was created at

core.bank.get_balance(member)

Gets the current balance of a member.

Parameters:member (discord.Member) – A discord.py member object.
Returns:The balance for the specified member
Return type:int
coroutine core.bank.set_balance(member, amount)

Sets the account balance for the member.

Parameters:
  • member (discord.Member) – A discord.py member object.
  • amount (int) – The amount to set the balance to
Returns:

New account balance

Return type:

int

Raises:

ValueError – if amount is less than 0

coroutine core.bank.withdraw_credits(member, amount)

Removes a certain amount of credits from an account.

Parameters:
  • member (discord.Member) – A discord.py member object.
  • amount (int) – The amount to withdraw
Returns:

New account balance

Return type:

int

Raises:

ValueError – if the amount is invalid or the account has insufficient funds

coroutine core.bank.deposit_credits(member, amount)

Adds a given amount of credits to an account.

Parameters:
  • member (discord.Member) – A discord.py member object.
  • amount (int) – The amount to set the balance to
Returns:

New account balance

Return type:

int

Raises:

ValueError – if the amount is invalid

coroutine core.bank.transfer_credits(from_, to, amount)

Transfers a given amount of credits from one account to another.

Parameters:
  • from (discord.Member) – The member to transfer from.
  • to (discord.Member) – The member to transfer to
  • amount (int) – The amount to transfer
Returns:

New balance for the account being transferred to

Return type:

int

Raises:

ValueError – if the amount is invalid or _from has insufficient funds

core.bank.can_spend(member, amount)

Determines if a member can spend the given amount.

Parameters:
  • member (discord.Member) – A discord.py member object.
  • amount (int) – The amount the account wants to spend
Returns:

True if the account can spend the amount, otherwise False

Return type:

bool

coroutine core.bank.wipe_bank(user)

Deletes all accounts from the bank

Parameters:user (discord.User or discord.Member) – a user to be used for wiping the bank
core.bank.get_guild_accounts(guild)

Gets all account data for the given guild

Parameters:guild (discord.Guild) – A discord.py guild object
Returns:List of account objects
Return type:list(Account)
Raises:RuntimeError – if the bank is currently global. Use get_global_accounts() to get all accounts if the bank is global
core.bank.get_global_accounts(user)

Gets all global account data

Parameters:user (discord.User) – a discord.py user object
Returns:List of account objects
Return type:list(Account)
Raises:RuntimeError – if the bank is currently guild specific. Use get_guild_accounts() to get all accounts for a guild if the bank is guild-specific
core.bank.get_account(member)

Gets the appropriate account for the given member.

Parameters:member (discord.User or discord.Member) – the account to get
Returns:The account for the specified member
Return type:Account
core.bank.is_global()

Determines if the bank is currently global.

Returns:True if bank is global, else False
Return type:bool
coroutine core.bank.set_global(global, user)

Sets global status of the bank

Important

All accounts are reset when you switch!

Parameters:
  • global – True will set bank to global mode.
  • user – Must be a Member object if changing TO global mode.
Returns:

New bank mode, True is global.

core.bank.get_bank_name(guild)

Gets the current bank name. If the bank is guild-specific the guild parameter is required.

Parameters:guild (discord.Guild) – The guild to get the bank name for (required if the bank is guild-specific)
Returns:the bank name
Return type:str
Raises:RuntimeError – if guild parameter is missing and required
coroutine core.bank.set_bank_name(name, guild)

Sets the bank name. If the bank is guild-specific the guild parameter is required.

Parameters:
  • name (str) – The new name for the bank
  • guild (discord.Guild) – The guild to set the bank name for (required if the bank is guild-specific)
Returns:

the new name for the bank

Return type:

str

Raises:

RuntimeError – if guild parameter is missing and required

core.bank.get_currency_name(guild)

Gets the currency name for the bank. If the bank is guild-specific the guild parameter is required.

Parameters:guild (discord.Guild) – The guild to get the currency name for (required if the bank is guild-specific)
Returns:the currency name
Return type:str
Raises:RuntimeError – if guild parameter is missing and required
coroutine core.bank.set_currency_name(name, guild)

Sets the currency name for the bank. If the bank is guild-specific the guild parameter is required.

Parameters:
  • name (str) – The new currency name for the bank
  • guild (discord.Guild) – The guild to set the currency name for (required if the bank is guild-specific)
Returns:

the new currency name for the bank

Return type:

str

Raises:

RuntimeError – if guild parameter is missing and required

core.bank.get_default_balance(guild)

Gets the current default balance amount. If the bank is guild-specific you must pass guild.

Parameters:guild (discord.Guild) – The guild to get the default balance for
Returns:the default balance
Return type:int
Raises:RuntimeError – if the guild parameter is missing and required
coroutine core.bank.set_default_balance(amount, guild)

Sets the default balance amount. If the bank is guild-specific you must pass guild.

Parameters:
  • amount (int) – The new amount for the default balance
  • guild (discord.Guild) – The guild to set the default balance for
Returns:

the new default balance

Return type:

int

Raises:
  • RuntimeError – if the guild parameter is missing and required
  • ValueError – if the new amount is invalid