【发布时间】:2020-12-21 19:01:24
【问题描述】:
我正在尝试使用给定命令创建积分系统,例如,如果用户完成挑战,mod 可以给用户积分,我已经为它创建了一个函数,将用户 ID 和 0 积分写入 .json当他们加入时(第一个框),但我似乎无法正确获取 give 命令(第二个框),并且没有出现错误,任何帮助将不胜感激,在此先感谢 :)
async def update_data(users, user): #
if not user.id in users: #i called this in the member join event
users[user.id] = {}
users[user.id]['points'] = 0
这个函数应该是加分的:
async def add_points(ctx, users, user, pts): #I wrote that function at the beginning of the script
users[user.id]['points'] += pts
这是给定命令:
@client.command(pass_context = True)
async def give(ctx, member, amount):
with open('users.json', 'r') as f:
users = json.load(f)
await add_points(users, member, amount)
with open('users.json', 'w') as f:
json.dump('users', 'f')
await ctx.send(f'given {member} {amount} programming points')
(抱歉信息不足)
【问题讨论】:
标签: python discord bots discord.py