-1
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

enter image description here

I created a discord bot for chat management, I entered that all user data (WARNS, CAPS) should be entered in the .json file, but it doesn't open the file to enter the .json data in the temporary variable, I forgot forum, but I did not find a similar problem and the solution to this problem This is my code:

    import discord
    from Token import Token
    import sys
    import os
    import json
    import time
    from discord.ext import commands
    from discord.utils import get
    client= discord.Client()
    BADWORDS = ["fuck", "suck", "dum", "looser", "losser"]
    LINKS = ["http", "https", "://", ".ru", ".com",".net", ".org", ".biz", ".gg"]
    
    if not os.path.exists('users.json'):
        with open("users.json","w") as file:
            file.write("{}\n".format(str))
            file.close()
    
    @client.event
    async def on_ready():
        print('We are loged as {0.user}'.format(client))
        for guild in client.guilds:
            for member in guild.members:    
                with open('users.json','r') as file :
                    data = json.load(file)
                    file.close()
                with open("users.json","w") as file :
                    data[str(member.id)] = {
                        "WARNS": 0,
                        "CAPS": 0
                    },
    
                    json.dump(data, file, indent=4)
                    file.close()
    @client.event
    async def on_message(message):
        WARN = BADWORDS + LINKS
      
        for i in range(0, len(WARN)):
            if WARN[i] in message.content.lower():
                await message.delete()
                with open("users.json","r") as file:
                    data = json.load()
                    file.close()
      
                with open("users.json","w") as file:
                    data[str(message.author.id)]["WARNS"] += 1
                    json.dump(data, file, indent=4)
                    file.close()
                emb = discord.Embed(
                    title="Rules Ignored",
                    description=f"*Rcent he have {data[str(message.author.id)]['WARNS'] - 1} rulles ignored, if he continued 7 times he will have BAN!",
                    timestamp=message.created_at
                    )
                emb.add_field(name = "Chanel:", value= message.chanel.mention, inline=True)
                emb.add_field(name = "User:", value=message.author.mention, inline=True)
                emb.add_field(name = "Type of Rules: ", value="Badword/Lincks", inline=True)
      
                await get(message.guild.text_chanels, id=1004729057277120624).send(embed=emb)
      
                if data[str(message.author.id)]['WARNS'] >= 7:
                    await message.author.ban(reason= "You was banned becouse you Ignored Rules 7 times")
        
            if message.content.isupper():
                with open("users.json","r") as file:
                    data = json.load(file)
                    file.close()
      
                with open('users.json','w') as file:
                    data[str(message.author.id)]["CAPS"] += 1
                    json.dump(data, file, indent=4)
                    file.close()
      
                if data[str(message.author.id)]["CAPS"] >= 3:
                    with open("users.json","w") as file:
                        data[str(message.author.id)]["CAPS"] = 0
                        data[str(message.author.id)]["WARNS"] = 1
                        json.dump(data, file, indent=4)
                        file.close()
        
                    emb = discord.Embed(
                        title="Rules Ignored",
                        description=f"*in the past he have {data[str(message.author.id)]['WARNS'] - 1} rulles ignored, if he continued 7 times he will have BAN!",
                        timestamp=message.created_at
                        )
                    emb.add_field(name = "Chanel:", value= message.chanel.mention, inline=True)
                    emb.add_field(name = "User:", value=message.author.mention, inline=True)
                    emb.add_field(name = "Type of Rules: ", value="CAPS", inline=True)
      
                    await get(message.guild.text_chanels, id=1004729057277120624).send(embed=emb)
      
    
    client.run(Token.token)

Markus
  • 5,976
  • 5
  • 6
  • 21
SiriyiuS
  • 3
  • 6
  • 1
    Does this answer your question? [JSONDecodeError: Expecting value: line 1 column 1 (char 0)](https://stackoverflow.com/questions/16573332/jsondecodeerror-expecting-value-line-1-column-1-char-0) – puncher Aug 06 '22 at 11:48
  • 1
    You may have broken data - please [edit] the question to include the json file. – Eric Jin Aug 06 '22 at 12:11
  • json file is empty, in the code there is a function which, according to the idea, will insert the tables into those json files { (user) "warns" :0 "caps" :0 } and so for each user – SiriyiuS Aug 07 '22 at 03:48
  • puncher I tryed but it doesn't work :( – SiriyiuS Aug 07 '22 at 04:03

2 Answers2

0

I think you need to place curly brackets in the json file like this.

{}

You don't need to fill these brackets. Just put these in the your file and then try again.

qRnt
  • 35
  • 7
0

You put .format(str)

   if not os.path.exists('users.json'):
        with open("users.json","w") as file:
            file.write("{}\n".format(str))
            file.close()

This writes: <class 'str'> in the json file

This wont work, if you checked the json file you would've seen. Just remove the .format(str) part and it should work.

  • yes, it is already working, but he does not want to register in json, at the time of registration he gives me key error , I add ["ID"] in json, and register message author id in ["ID"] but he gives me type error STR, i convert him in INT, but he gives me same type error but now is not correct INT type o_0 – SiriyiuS Aug 07 '22 at 19:18