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 propagate 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)[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)[source]¶ Set an account balance.
Parameters: - member (Union[discord.Member, discord.User]) – 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.
- RuntimeError – If the bank is guild-specific and a discord.User object is provided.
- BalanceTooHigh – If attempting to set the balance to a value greater than
bank._MAX_BALANCE
.
-
await
redbot.core.bank.
withdraw_credits
(member, amount)[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.
- TypeError – If the withdrawal amount is not an
int
.
-
await
redbot.core.bank.
deposit_credits
(member, amount)[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.
- TypeError – If the deposit amount is not an
int
.
-
await
redbot.core.bank.
can_spend
(member, amount)[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:
-
await
redbot.core.bank.
transfer_credits
(from_, to, amount)[source]¶ Transfer a given amount of credits from one account to another.
Parameters: - from_ (Union[discord.Member, discord.User]) – The member to transfer from.
- to (Union[discord.Member, discord.User]) – The member to transfer to.
- amount (int) – The amount to transfer.
Returns: The new balance of the member gaining credits.
Return type: Raises: - ValueError – If the amount is invalid or if
from_
has insufficient funds. - TypeError – If the amount is not an
int
. - RuntimeError – If the bank is guild-specific and a discord.User object is provided.
- BalanceTooHigh – If the balance after the transfer would be greater than
bank._MAX_BALANCE
.
-
await
redbot.core.bank.
wipe_bank
(guild=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)[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
-
await
redbot.core.bank.
is_global
()[source]¶ Determine if the bank is currently global.
Returns: True
if the bank is global, otherwiseFalse
.Return type: bool
-
await
redbot.core.bank.
set_global
(global_)[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)[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)[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.
-
await
redbot.core.bank.
get_currency_name
(guild=None)[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)[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.
-
await
redbot.core.bank.
get_default_balance
(guild=None)[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)[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 less than 0 or higher than the max allowed balance.
-
await
redbot.core.bank.
get_max_balance
(guild=None)[source]¶ Get the max balance for the bank.
Parameters: guild ( discord.Guild
, optional) – The guild to get the max balance for (required if bank is guild-specific).Returns: The maximum allowed balance. Return type: int Raises: RuntimeError – If the bank is guild-specific and guild was not provided.
-
await
redbot.core.bank.
set_max_balance
(amount, guild=None)[source]¶ Set the maximum balance for the bank.
Parameters: - amount (int) – The new maximum balance.
- guild (
discord.Guild
, optional) – The guild to set the max balance for (required if bank is guild-specific).
Returns: The new maximum balance.
Return type: Raises: - RuntimeError – If the bank is guild-specific and guild was not provided.
- ValueError – If the amount is less than 0 or higher than 2 ** 63 - 1.
-
await
redbot.core.bank.
bank_prune
(bot, guild=None, user_id=None)[source]¶ Prune bank accounts from the bank.
Parameters: - bot (Red) – The bot.
- guild (discord.Guild) – The guild to prune. This is required if the bank is set to local.
- user_id (int) – The id of the user whose account will be pruned. If supplied this will prune only this user’s bank account otherwise it will prune all invalid users from the bank.
Raises: BankPruneError – If guild is
None
and the bank is Local.