Я не могу понять, что не так с кодом! Предполагается, что он должен взять имя сервера и людей и создать базу данных с именами всех на сервере.
@client.event
async def on_message(message):
if message.content.startswith("setup"):
try:
with open("users.json") as json_file:
data = json.load(json_file)
for m in data[message.guild]:
await ctx.send("Setup has done already!")
except:
from os.path import isfile
if isfile('users.json'): # check if file exists
with open('users.json', 'r') as infile:
data = json.load(infile)
guildset = str(message.guild)
data[guildset] = [] # load from existing
with open("users.json", "w") as outfile:
json.dump(data, outfile)
with open("users.json") as json_file:
data = json.load(json_file)
guild = message.guild
for members1 in guild.members:
guild = message.guild
guildset = str(guild)
for m in data[guildset]:
members2 = str(members1)
m[members2].append({
"money": 0,
"count": 0,
"other": 0
})
with open("users.json", "w") as outfile:
json.dump(data, outfile)
C:\Users\xzyte\Desktop\ZTZ> cmd /C "set "DEBUGPY_LAUNCHER_PORT=51998" && C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\python.exe c:\Users\xzyte\.vscode\extensions\ms-python.python-2020.4.76186\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher c:\Users\xzyte\Desktop\ZTZ\main.py "
Traceback (most recent call last):
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\xzyte\.vscode\extensions\ms-python.python-2020.4.76186\pythonFiles\lib\python\debugpy\no_wheels\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\xzyte\.vscode\extensions\ms-python.python-2020.4.76186\pythonFiles\lib\python\debugpy\no_wheels\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\xzyte\.vscode\extensions\ms-python.python-2020.4.76186\pythonFiles\lib\python\debugpy\no_wheels\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 262, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 237, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "c:\Users\xzyte\Desktop\ZTZ\main.py", line 58
else: # no file, start from scratch
^
SyntaxError: invalid syntax
C:\Users\xzyte\Desktop\ZTZ> cmd /C "set "DEBUGPY_LAUNCHER_PORT=52010" && C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\python.exe c:\Users\xzyte\.vscode\extensions\ms-python.python-2020.4.76186\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher c:\Users\xzyte\Desktop\ZTZ\main.py "
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "c:\Users\xzyte\Desktop\ZTZ\main.py", line 42, in on_message
data = json.load(json_file)
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
C:\Users\xzyte\Desktop\ZTZ> cmd /C "set "DEBUGPY_LAUNCHER_PORT=52040" && C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\python.exe c:\Users\xzyte\.vscode\extensions\ms-python.python-2020.4.76186\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher c:\Users\xzyte\Desktop\ZTZ\main.py "
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "c:\Users\xzyte\Desktop\ZTZ\main.py", line 42, in on_message
data = json.load(json_file)
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\xzyte\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)