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
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¶
-
class
redbot.core.bank.
Account
(name: str, balance: int, created_at: datetime.datetime)[source]¶ A single account.
This class should ONLY be instantiated by the bank itself.
-
coroutine
redbot.core.bank.
get_balance
(member: discord.member.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
-
coroutine
redbot.core.bank.
set_balance
(member: discord.member.Member, amount: int) → 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: Raises: ValueError
– If attempting to set the balance to a negative number.
-
coroutine
redbot.core.bank.
withdraw_credits
(member: discord.member.Member, amount: int) → 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: Raises: ValueError
– If the withdrawal amount is invalid or if the account has insufficient funds.
-
coroutine
redbot.core.bank.
deposit_credits
(member: discord.member.Member, amount: int) → 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: Raises: ValueError
– If the deposit amount is invalid.
-
coroutine
redbot.core.bank.
can_spend
(member: discord.member.Member, amount: int) → 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, elseFalse
.Return type:
-
coroutine
redbot.core.bank.
transfer_credits
(from_: discord.member.Member, to: discord.member.Member, amount: int)[source]¶ Transfer 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: The new balance.
Return type: Raises: ValueError
– If the amount is invalid or iffrom_
has insufficient funds.
-
coroutine
redbot.core.bank.
get_guild_accounts
(guild: discord.guild.Guild) → typing.List[redbot.core.bank.Account][source]¶ Get all account data for the given guild.
Parameters: guild (discord.Guild) – The guild to get accounts for. Returns: A list of all guild accounts. Return type: list
ofAccount
Raises: RuntimeError
– If the bank is currently global.
-
coroutine
redbot.core.bank.
get_global_accounts
() → typing.List[redbot.core.bank.Account][source]¶ Get all global account data.
Returns: A list of all global accounts. Return type: list
ofAccount
Raises: RuntimeError
– If the bank is currently guild specific.
-
coroutine
redbot.core.bank.
get_account
(member: typing.Union[discord.member.Member, discord.user.User]) → 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
ordiscord.Member
) – The user whose account to get.Returns: The user’s account. Return type: Account
-
coroutine
redbot.core.bank.
is_global
() → bool[source]¶ Determine if the bank is currently global.
Returns: True
if the bank is global, otherwiseFalse
.Return type: bool
-
coroutine
redbot.core.bank.
set_global
(global_: bool) → 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 adiscord.Member
was not provided.
-
coroutine
redbot.core.bank.
get_bank_name
(guild: discord.guild.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.
-
coroutine
redbot.core.bank.
set_bank_name
(name: str, guild: discord.guild.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: Raises: RuntimeError
– If the bank is guild-specific and guild was not provided.
-
coroutine
redbot.core.bank.
get_currency_name
(guild: discord.guild.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.
-
coroutine
redbot.core.bank.
set_currency_name
(name: str, guild: discord.guild.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: Raises: RuntimeError
– If the bank is guild-specific and guild was not provided.
-
coroutine
redbot.core.bank.
get_default_balance
(guild: discord.guild.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.
-
coroutine
redbot.core.bank.
set_default_balance
(amount: int, guild: discord.guild.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: Raises: RuntimeError
– If the bank is guild-specific and guild was not provided.ValueError
– If the amount is invalid.