Цель команды - добавить точку (монету) к упомянутому пользователю (и добавить их в базу данных, если их еще нет в ней), но я получаю NameError: name 'member' не определен.
@client.command()
async def gift(ctx,*, member : discord.Member):
with open('users.json', 'r') as f:
users = json.load(f)
await update_data(users, member.id)
await add_coin(users, member.id, 1)
with open('users.json', 'w') as f:
users = json.dump(f)
async def update_data(users, user):
if not member.id in users:
users[member.id] = {}
users[member.id]['coins'] = 0
async def add_coin(users, user, coin):
users[member.id]['coins'] += coin
await ctx.send(f'{member.id} has {coin} coins')
Трассировка:
Ignoring exception in command gift:
Traceback (most recent call last):
File "C:\Users\Kiaza\AppData\Local\Programs\Python\Python36\lib\site-packages\
discord\ext\commands\core.py", line 79, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Kiaza\Documents\discord bot\bot.py", line 57, in gift
await update_data(users, member.id)
File "C:\Users\Kiaza\Documents\discord bot\bot.py", line 64, in update_data
if not member.id in users:
NameError: name 'member' is not defined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Kiaza\AppData\Local\Programs\Python\Python36\lib\site-packages\
discord\ext\commands\bot.py", line 863, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Kiaza\AppData\Local\Programs\Python\Python36\lib\site-packages\
discord\ext\commands\core.py", line 728, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Kiaza\AppData\Local\Programs\Python\Python36\lib\site-packages\
discord\ext\commands\core.py", line 88, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'member' is not defined