how do you deposit the money in discordpy?

You could try something like this:

@client.command()
async def deposit (ctx, amount=0):
    await ctx.message.delete()
    embed = discord.Embed(
        color=0xa61022
    )
    
    try:
        amount = int(amount)
        if amount == 0:
            embed.set_author(
                name="Per favore specifica la somma che vuoi rimuovere!",
            )
            await ctx.send(embed=embed, delete_after=10.0)
            return
        if amount < 0:
            embed.set_author(
                name="Non inserire numeri negativi!",
            )
            await ctx.send(embed=embed, delete_after=10.0)
            return

    except:
        if amount == "all":
            # Deposit all code
        else:
            # Invalid amount 

    id_author = str(ctx.author.id)
    if id_author not in economy_system:
        economy_system[id_author] = {}
        embed.set_author(
            name=f"{ctx.author.name} non ha un account!"
        )
        await ctx.send(embed=embed, delete_after=10)
        return
    economy_system[id_author]["wallet"] -= amount
    if economy_system[id_author]["wallet"] < 0:
        print("a")
        embed.set_author(
            name=f"Non puoi depositare più di quanto hai!"
        )
        economy_system[id_author]["wallet"] += amount
        await ctx.send(embed=embed, delete_after=10)
        return
    economy_system[id_author]["bank"] += amount
    embed.set_author(
        name=f"Hai depositato {amount}€!"
    )
    await ctx.send(embed=embed, delete_after=10)
    return

Also I suggest you merge the 0 and < 0 if statement seeing as they do almost the exact same thing, maybe simplifying it down to this:

@client.command()
async def deposit (ctx, amount=0):
    valid = True
    await ctx.message.delete()
    embed = discord.Embed(color=0xa61022)

    try:
        amount = int(amount)
        if amount <= 0:
            valid = False
            message = "Per favore specifica la somma che vuoi rimuovere!"
    except:
        if amount == "all":
            # Deposit all code
        else:
            valid = False
            # Invalid amount code

    id_author = str(ctx.author.id)
    if valid and id_author not in economy_system:
        valid = False
        economy_system[id_author] = {}
        message = f"{ctx.author.name} non ha un account!"

    economy_system[id_author]["wallet"] -= amount
    if valid and economy_system[id_author]["wallet"] < 0:
        print("a")
        message = f"Non puoi depositare più di quanto hai!"
        economy_system[id_author]["wallet"] += amount
    elif valid:
        economy_system[id_author]["bank"] += amount
        message = f"Hai depositato {amount}€!"

    embed.set_author(name=message)
    await ctx.send(embed=embed, delete_after=10)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top