【问题标题】:Buying temp role command in economy bot在经济机器人中购买临时角色命令
【发布时间】:2020-12-24 18:47:38
【问题描述】:

我正在通过 json 文件制作一个经济机器人。我需要命令帮助,它可以从 json 文件中的用户余额中删除一些钱,并为他添加一周或一个月的角色。

如果你有兴趣,还有我的辅助函数:

async def open_account(user):
    
    users = await get_bank_data()


    if str(user.id) in users:
        return False
    else:
        users[str(user.id)] = {}
        users[str(user.id)]["wallet"] = 0

    with open("mainbank.json", "w") as f:
        json.dump(users, f)

    return True


async def update_bank(user, change = 0, mode = "wallet"):
    users = await get_bank_data()

    users[str(user.id)][mode] += change

    with open("mainbank.json", "w") as f:
        json.dump(users, f)

    bal = users[str(user.id)]["wallet"]

    return bal

我不知道如何实现,如果有,请写在答案中

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:
    @Bot.command()
    async def command_name(ctx):
        role = ctx.guild.get_role(role_id)
        await open_account(ctx.author)
    
        user = ctx.author
    
        bal = await update_bank(user)
    
        if 2500>bal:
            await ctx.send("You don't have that much money")
            return
    
        await update_bank(user, -2500, "wallet")
    
        await user.add_roles(sub_role)
    
        emb = discord.Embed(description = "You bought role for a week!", color = 0x2ecc71)
        await ctx.send(embed = emb)
    
        await asyncio.sleep(604800)
        await user.remove_roles(sub_role)
    

    【讨论】:

      猜你喜欢
      • 2021-04-12
      • 1970-01-01
      • 2021-08-30
      • 2021-09-03
      • 2021-01-18
      • 2021-05-25
      • 2021-04-16
      • 2021-03-13
      • 1970-01-01
      相关资源
      最近更新 更多