Bank

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

Basic Usage

from redbot.core import bank, commands
import discord

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

API Reference

Bank

@redbot.core.bank.cost(amount)[source]

Decorates a coroutine-function or command to have a cost.

If the command raises an exception, the cost will be refunded.

You can intentionally refund by raising AbortPurchase (this error will be consumed and not show to users)

Other exceptions will propogate and will be handled by Red’s (and/or any other configured) error handling.

class redbot.core.bank.Account(name, balance, created_at)[source]

Bases: object

A single account.

This class should ONLY be instantiated by the bank itself.

await redbot.core.bank.get_balance(member) → int[source]

Get the current balance of a member.

Parameters:member (discord.Member) – The member whose balance to check.
Returns:The member’s balance
Return type:int
await redbot.core.bank.set_balance(member, amount) → int[source]

Set an account balance.

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

New account balance.

Return type:

int

Raises:
  • ValueError – If attempting to set the balance to a negative number.
  • BalanceTooHigh – If attempting to set the balance to a value greater than bank.MAX_BALANCE
await redbot.core.bank.withdraw_credits(member, amount) → int[source]

Remove a certain amount of credits from an account.

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

New account balance.

Return type:

int

Raises:
  • ValueError – If the withdrawal amount is invalid or if the account has insufficient funds.
  • TypeError – If the withdrawal amount is not an int.
await redbot.core.bank.deposit_credits(member, amount) → int[source]

Add a given amount of credits to an account.

Parameters:
  • member (discord.Member) – The member to deposit credits to.
  • amount (int) – The amount to deposit.
Returns:

The new balance.

Return type:

int

Raises:
await redbot.core.bank.can_spend(member, amount) → bool[source]

Determine if a member can spend the given amount.

Parameters:
  • member (discord.Member) – The member wanting to spend.
  • amount (int) – The amount the member wants to spend.
Returns:

True if the member has a sufficient balance to spend the amount, else False.

Return type:

bool

await redbot.core.bank.transfer_credits(from_, to, amount)[source]

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

Parameters:
Returns:

The new balance of the member gaining credits.

Return type:

int

Raises:
  • ValueError – If the amount is invalid or if from_ has insufficient funds.
  • TypeError – If the amount is not an int.
await redbot.core.bank.wipe_bank(guild = None) → None[source]

Delete all accounts from the bank.

Parameters:guild (discord.Guild) – The guild to clear accounts for. If unsupplied and the bank is per-server, all accounts in every guild will be wiped.
await redbot.core.bank.get_account(member) → redbot.core.bank.Account[source]

Get the appropriate account for the given user or member.

A member is required if the bank is currently guild specific.

Parameters:member (discord.User or discord.Member) – The user whose account to get.
Returns:The user’s account.
Return type:Account
await redbot.core.bank.is_global() → bool[source]

Determine if the bank is currently global.

Returns:True if the bank is global, otherwise False.
Return type:bool
await redbot.core.bank.set_global(global_) → bool[source]

Set global status of the bank.

Important

All accounts are reset when you switch!

Parameters:global_ (bool) – True will set bank to global mode.
Returns:New bank mode, True is global.
Return type:bool
Raises:RuntimeError – If bank is becoming global and a discord.Member was not provided.
await redbot.core.bank.get_bank_name(guild = None) → str[source]

Get the current bank name.

Parameters:guild (discord.Guild, optional) – The guild to get the bank name for (required if bank is guild-specific).
Returns:The bank’s name.
Return type:str
Raises:RuntimeError – If the bank is guild-specific and guild was not provided.
await redbot.core.bank.set_bank_name(name, guild = None) → str[source]

Set the bank name.

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

The new name for the bank.

Return type:

str

Raises:

RuntimeError – If the bank is guild-specific and guild was not provided.

await redbot.core.bank.get_currency_name(guild = None) → str[source]

Get the currency name of the bank.

Parameters:guild (discord.Guild, optional) – The guild to get the currency name for (required if bank is guild-specific).
Returns:The currency name.
Return type:str
Raises:RuntimeError – If the bank is guild-specific and guild was not provided.
await redbot.core.bank.set_currency_name(name, guild = None) → str[source]

Set the currency name for the bank.

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

The new name for the currency.

Return type:

str

Raises:

RuntimeError – If the bank is guild-specific and guild was not provided.

await redbot.core.bank.get_default_balance(guild = None) → int[source]

Get the current default balance amount.

Parameters:guild (discord.Guild, optional) – The guild to get the default balance for (required if bank is guild-specific).
Returns:The bank’s default balance.
Return type:int
Raises:RuntimeError – If the bank is guild-specific and guild was not provided.
await redbot.core.bank.set_default_balance(amount, guild = None) → int[source]

Set the default balance amount.

Parameters:
  • amount (int) – The new default balance.
  • guild (discord.Guild, optional) – The guild to set the default balance for (required if bank is guild-specific).
Returns:

The new default balance.

Return type:

int

Raises:
  • RuntimeError – If the bank is guild-specific and guild was not provided.
  • ValueError – If the amount is invalid.
exception redbot.core.bank.AbortPurchase[source]

Bases: Exception