一样,对比前面的match档,现在新增一个bank的json档案
回到bot档,现在我们必须撰写2个部分,一个是读取,一个是确认你的这个key是否存在......
# cogs/includebanksystem.py
async def open_account(user):
pass
# 省略
async def get_bank_data():
pass
async def open_account(user):
users = await get_bank_data()
if str(user.id) in users:
return False
else:
# 省略
with open("bank.json", "w") as f:
json.dump(users, f)
return True
async def get_bank_data():
with open("bank.json", "r")as f:
users = json.load(f)
return users
users[str(user.id)] = {}
users[str(user.id)]["wallet"] = 0
users[str(user.id)]["bank"] = 0
{
}
# 略
@commands.command()
async def money(self, ctx):
await open_account(ctx.author)
user = ctx.author
users = await get_bank_data()
wallet = users[str(user.id)]["wallet"]
bank = users[str(user.id)]["bank"]
em = discord.Embed(title = f"{ctx.author.name}'s 钱包", color = discord.Color.red())
em.set_thumbnail(url = user.avatar_url)
em.add_field(name = "Wallet", value = wallet)
em.add_field(name = "Bank", value = bank)
await ctx.send(embed = em)
# 略
shop = [
{"name": "Watch", "price": 8},
{"name": "Laptop", "price": 87},
{"name": "PC", "price": 870},
{"name": "PS5", "price": 690},
{"name": "Cat", "price": 1000}
]
@commands.command()
async def market(self, ctx):
pass
em = discord.Embed(title = "market", color = 0x6345)
em.set_thumbnail(url = "https://www.formula-ai.com/wp-content/uploads/2020/09/python_or_java_meme.jpg")
for item in shop:
name = item["name"]
price = item["price"]
em.add_field(name = name, value = f"${price}")
await ctx.send(embed = em)
<<: 【PHP Telegram Bot】Day09 - 用 PHP 主动接收和发送讯息吧!
Mutation 提交mutation,是更动state的唯一方法,并以state为第一个参数。 包...
学习目的: JavaScrip语言是网站客服端的最佳动态利器,想要制作一个生动的网页肯定不能少了他。...
欲找,RS可以指定汇出的档案名称否,结果看到这个. URL access parameter ref...
一. LSTM的问题 LSTM虽然非常强大,但LSTM也是有一个问题,就是计算时间较久导致执行速度较...
今天预计讲解下面两个 (也就是下图的步骤 5) API 的 JSON 内容 把内容加上 Nonce ...