Enhance business command in Unbelievaboat by adding detailed user feedback and error handling. This update ensures that users receive their current balance, business cost, and maximum balance information when attempting to start a business, improving clarity and user experience. Additionally, it introduces error handling for credit withdrawal failures, providing more informative responses in case of issues.
Some checks failed
Run pre-commit / Run pre-commit (push) Has been cancelled

This commit is contained in:
Valerie 2025-05-28 22:03:08 -04:00
parent 44e8bc79ee
commit 6d50c3279d

View file

@ -171,19 +171,39 @@ class Business(commands.Cog):
if len(businesses) >= 3:
return await ctx.send("You can only own up to 3 businesses!")
cost = business_types[business_type]["cost"]
if not await bank.can_spend(ctx.author, cost):
return await ctx.send(f"You need ${cost:,} to start this business!")
cost = int(business_types[business_type]["cost"]) # Ensure cost is an integer
current_balance = await bank.get_balance(ctx.author)
max_balance = await bank.get_max_balance(ctx.guild)
await bank.withdraw_credits(ctx.author, cost)
businesses[business_name] = {
"type": business_type,
"employees": business_types[business_type]["employees"]["min"],
"upgrades": [],
"last_collection": None
}
await ctx.send(f"Congratulations! You are now the proud owner of {business_name}!")
# Debug information
debug_msg = (
f"Debug Info:\n"
f"- Your current balance: ${current_balance:,}\n"
f"- Business cost: ${cost:,}\n"
f"- Max possible balance: ${max_balance:,}\n"
f"- Can spend: {await bank.can_spend(ctx.author, cost)}"
)
await ctx.send(debug_msg)
if not await bank.can_spend(ctx.author, cost):
return await ctx.send(
f"You need ${cost:,} to start this business! "
f"(You have ${current_balance:,})"
)
try:
await bank.withdraw_credits(ctx.author, cost)
businesses[business_name] = {
"type": business_type,
"employees": business_types[business_type]["employees"]["min"],
"upgrades": [],
"last_collection": None
}
await ctx.send(f"Congratulations! You are now the proud owner of {business_name}!")
except ValueError as e:
await ctx.send(f"Error occurred while trying to withdraw credits: {str(e)}")
except Exception as e:
await ctx.send(f"An unexpected error occurred: {str(e)}")
@business.command(name="view")
async def view_business(self, ctx, *, business_name: str = None):