-1

I was interested in making a discord bot an im following a tutorial (https://www.youtube.com/watch?v=-WlLazqQO3I)

I've barely learnt python so i only understand a bit of this code, so i need help fixing the problem.

code: https://pastebin.com/BZJ84VKu

m = {}

@client.event
async def on_ready():
    global m
    with open(YOURFILENAME, "r") as j:
        m = json.load(j)
        j.close()
    if len(m) == 0:
        m = {}
        for member in client.get_guild(YOURGUILDSID).members:
            m[str(member.id)] = {"xp": 0, "messageCountdown": 0}
    print("ready")
    while True:
        try:
            for member in client.get_guild(YOURGUILDSID).members:
                m[str(member.id)]["messageCountdown"] -= 1
        except:
            pass
            await asyncio.sleep(1)

https://pastebin.com/FnSMHEWN (error)

bot still works but when i try "!xp" a different error comes

Sparkz
  • 11
  • 5
  • What is the error? Did you create a variable that contains an actual filename for YOURFILENAME? If not, it cannot open the file because it doesn't exist. – raddevus May 14 '22 at 17:11
  • Ye, i created a variable and inside YOURFILENAME is lvl.json – Sparkz May 14 '22 at 17:14
  • replace m = json.load(j) with m = json.load(j.read()) – Bast May 14 '22 at 17:17
  • @Bast im getting a problem : Expected type 'SupportsRead[Union[str, bytes]]', got 'str' instead – Sparkz May 14 '22 at 17:22
  • Check this out, it is probably your answer: https://stackoverflow.com/questions/37974199/writing-to-io-bytesio-in-csv-fails-in-python3 – raddevus May 14 '22 at 17:29

0 Answers0