我试图制作一个代码,这样你就可以在使用命令时给另一个用户你的硬币,但它不起作用...... 代码:
#Give coins command
@client.command()
async def give(ctx, member:discord.Member, amount):
with open("Stats.json", "r") as f:
stats = json.load(f)
coins = stats[str(ctx.message.author.id)]["Coins"]
if ctx.guild.member(member.id):
if coins >= amount:
coins -= amount
stats[str(member.id)]["Coins"] += amount
with open("Stats.json", "w") as f:
json.dump(stats, f, indent = 4)
这里是存储数据的文件(Stats.json):
{
"412255211567185920": {
"Exp": 3321,
"Lvl": 7,
"ExpTime": 1620481093.411307,
"Coins": 111
},
"464297630923620353": {
"Exp": 149,
"Lvl": 3,
"ExpTime": 1620478482.821512,
"Coins": 0
}
}
当我输入 !give @Member 10
时,没有任何反应......
我也试过发出一个命令,管理员可以给自己硬币,但它不起作用。 代码:
#Make coins
@client.command()
@commands.has_permissions(administrator = True)
async def magic(ctx, amount):
with open("Stats.json", "r") as f:
stats = json.load(f)
user = ctx.message.author
coins = stats[str(user.id)]["Coins"]
coins += amount
with open("Stats.json", "w") as f:
json.dump(stats, f, indent = 4)