Table of contents
- Bank
- Basic Usage
- API Reference
- Bank
- @redbot.core.bank.cost(amount)
- exception redbot.core.bank.AbortPurchase
- class redbot.core.bank.Account(name, balance, created_at)
- class redbot.core.bank.BankPruneInformation(guild, user_id, pruned_users)
- class redbot.core.bank.BankSetBalanceInformation(recipient, guild, recipient_old_balance, recipient_new_balance)
- class redbot.core.bank.BankTransferInformation(sender, recipient, guild, transfer_amount, sender_new_balance, recipient_new_balance)
- class redbot.core.bank.PaydayClaimInformation(member, channel, message, amount, old_balance, new_balance)
- await redbot.core.bank.bank_prune(bot, guild=None, user_id=None)
- await redbot.core.bank.can_spend(member, amount)
- await redbot.core.bank.deposit_credits(member, amount)
- await redbot.core.bank.get_account(member)
- await redbot.core.bank.get_balance(member)
- await redbot.core.bank.get_bank_name(guild=None)
- await redbot.core.bank.get_currency_name(guild=None)
- await redbot.core.bank.get_default_balance(guild=None)
- await redbot.core.bank.get_leaderboard(positions=None, guild=None)
- await redbot.core.bank.get_leaderboard_position(member, , return_lb_size=False)
- await redbot.core.bank.get_max_balance(guild=None)
- await redbot.core.bank.is_global()
- redbot.core.bank.is_owner_if_bank_global()
- Example
- await redbot.core.bank.set_balance(member, amount)
- await redbot.core.bank.set_bank_name(name, guild=None)
- await redbot.core.bank.set_currency_name(name, guild=None)
- await redbot.core.bank.set_default_balance(amount, guild=None)
- await redbot.core.bank.set_global(global_)
- await redbot.core.bank.set_max_balance(amount, guild=None)
- await redbot.core.bank.transfer_credits(from_, to, amount)
- await redbot.core.bank.wipe_bank(guild=None)
- await redbot.core.bank.withdraw_credits(member, amount)
This page is generated from
docs/framework_bank.rst- please edit the source file instead of this page.
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 = commands.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)
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.
exception redbot.core.bank.AbortPurchase
Bases: Exception
class redbot.core.bank.Account(name, balance, created_at)
Bases: object
A single account.
This class should ONLY be instantiated by the bank itself.
class redbot.core.bank.BankPruneInformation(guild, user_id, pruned_users)
Bases: NamedTuple
guild
Alias for field number 0
pruned_users
Alias for field number 2
user_id
Alias for field number 1
class redbot.core.bank.BankSetBalanceInformation(recipient, guild, recipient_old_balance, recipient_new_balance)
Bases: NamedTuple
guild
Alias for field number 1
recipient
Alias for field number 0
recipient_new_balance
Alias for field number 3
recipient_old_balance
Alias for field number 2
class redbot.core.bank.BankTransferInformation(sender, recipient, guild, transfer_amount, sender_new_balance, recipient_new_balance)
Bases: NamedTuple
guild
Alias for field number 2
recipient
Alias for field number 1
recipient_new_balance
Alias for field number 5
sender
Alias for field number 0
sender_new_balance
Alias for field number 4
transfer_amount
Alias for field number 3
class redbot.core.bank.PaydayClaimInformation(member, channel, message, amount, old_balance, new_balance)
Bases: NamedTuple
amount
Alias for field number 3
channel
Alias for field number 1
member
Alias for field number 0
message
Alias for field number 2
new_balance
Alias for field number 5
old_balance
Alias for field number 4
await redbot.core.bank.bank_prune(bot, guild=None, user_id=None)
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
Noneand the bank is Local.
await redbot.core.bank.can_spend(member, amount)
Determine if a member can spend the given amount.
- Parameters:
- member (Union [discord.Member , discord.User , discord.Object ]) -- The member wanting to spend.
- amount (int) -- The amount the member wants to spend.
- Raises:
TypeError -- If the amount is not an
int. - Returns:
Trueif the member has a sufficient balance to spend the amount, elseFalse. - Return type: bool
await redbot.core.bank.deposit_credits(member, amount)
Add a given amount of credits to an account.
- Parameters:
- member (Union [discord.Member , discord.User , discord.Object ]) -- The member to deposit credits to.
- amount (int) -- The amount to deposit.
- Returns: The new balance.
- Return type: int
- Raises:
- ValueError -- If the deposit amount is invalid.
- TypeError -- If the deposit amount is not an
int.
await redbot.core.bank.get_account(member)
Get the appropriate account for the given user or member.
A member is required if the bank is currently guild specific.
- Parameters: member (Union [discord.Member , discord.User , discord.Object ]) -- The user whose account to get.
- Returns: The user's account.
- Return type: Account
await redbot.core.bank.get_balance(member)
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.get_bank_name(guild=None)
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.get_currency_name(guild=None)
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.get_default_balance(guild=None)
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.get_leaderboard(positions=None, guild=None)
Gets the bank's leaderboard
- Parameters:
- positions (
int) -- The number of positions to get - guild (discord.Guild) -- The guild to get the leaderboard of. If the bank is global and this is provided, get only guild members on the leaderboard
- positions (
- Returns:
The sorted leaderboard in the form of
(user_id, raw_account) - Return type:
listoftuple - Raises: TypeError -- If the bank is guild-specific and no guild was specified
await redbot.core.bank.get_leaderboard_position(member, , return_lb_size=False)
Get the leaderboard position for the specified user
- Parameters:
- member (
discord.Userordiscord.Member) -- The user to get the leaderboard position of. - return_lb_size (bool) -- Whether to return a tuple with the position and size of the leaderboard.
- member (
- Returns:
The position of the user on the leaderboard, if
return_lb_sizeisFalse(default) or a tuple of the position of the user and the total leaderboard size. The position may beNone, if the user is not on the leaderboard. - Return type:
Optional[
int] or Tuple[Optional[int],int] - Raises:
TypeError -- If the bank is currently guild-specific and a
discord.Userobject was passed in
await redbot.core.bank.get_max_balance(guild=None)
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.is_global()
Determine if the bank is currently global.
- Returns:
Trueif the bank is global, otherwiseFalse. - Return type: bool
redbot.core.bank.is_owner_if_bank_global()
Restrict the command to the bot owner if the bank is global, otherwise ensure it's used in guild (WITHOUT checking any user permissions).
When used on the command, this should be combined
with permissions check like redbot.core.commands.guildowner_or_permissions().
This is a command check.
Example
@bank.is_owner_if_bank_global()
@commands.guildowner()
@commands.group()
async def bankset(self, ctx: commands.Context):
"""Base command for bank settings."""
If the bank is global, the [p]bankset command can only be used by
the bot owners in both guilds and DMs.
If the bank is local, the command can only be used in guilds by guild and bot owners.
await redbot.core.bank.set_balance(member, amount)
Set an account balance.
- Parameters:
- member (Union [discord.Member , discord.User , discord.Object ]) -- 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.
- 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. - TypeError -- If the amount is not an
int.
await redbot.core.bank.set_bank_name(name, guild=None)
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.set_currency_name(name, guild=None)
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.set_default_balance(amount, guild=None)
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 less than 0 or higher than the max allowed balance.
- TypeError -- If the amount is not an
int.
await redbot.core.bank.set_global(global_)
Set global status of the bank.
IMPORTANT
All accounts are reset when you switch!
- Parameters:
global (bool) --
Truewill set bank to global mode. - Returns:
New bank mode,
Trueis global. - Return type: bool
- Raises:
RuntimeError -- If bank is becoming global and a
discord.Memberwas not provided.
await redbot.core.bank.set_max_balance(amount, guild=None)
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: int
- 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.
- TypeError -- If the amount is not an
int.
await redbot.core.bank.transfer_credits(from_, to, amount)
Transfer a given amount of credits from one account to another.
- Parameters:
- from (Union [discord.Member , discord.User , discord.Object ]) -- The member to transfer from.
- to (Union [discord.Member , discord.User , discord.Object ]) -- The member to transfer to.
- amount (int) -- The amount to transfer.
- 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. - 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.
- ValueError -- If the amount is invalid or if
await redbot.core.bank.wipe_bank(guild=None)
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.withdraw_credits(member, amount)
Remove a certain amount of credits from an account.
- Parameters:
- member (Union [discord.Member , discord.User , discord.Object ]) -- 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.
Installation Guides
- Installing Red
- Creating a bot account
- Updating Red
- Backing Up and Restoring Red
- About Virtual Environments
- Setting up auto-restart using batch on Windows
- Setting up auto-restart on Mac
- Setting up auto-restart using systemd on Linux
Cog Reference
User guides
- Getting started
- Running Red on Fluxer
- About Privileged Intents
- About public (big) bots
- Admin
- Alias
- Audio
- Cleanup
- Cog Manager UI
- Core
- CustomCommands
- Dev
- Downloader
- Economy
- Filter
- General
- Image
- Permissions
- Mod
- ModLog
- Mutes
- Reports
- Streams
- Trivia
- Warnings
- Red and End User Data
Cog Creation Guides
- Creating cogs for Red
- Slash Commands and Interactions
- Publishing cogs for Red
- Becoming an Approved Cog Creator
- Versioning
- End-user Guarantees
- Developer Guarantees
- Breaking Change Notices
Cog Development Framework Reference
- Shared API Keys
- Bank
- Bot
- Command Check Decorators
- App Command Check Decorators
- Commands Package
- App Commands Package
- Config
- Data Manager
- Custom Events
- Internationalization Framework
- Mod log
- RPC
- Tree
- Utility Functions
Others
Legacy (Red V2)