JSONDecodeError: Expecting value: line 1 column 1 (char 0) with discord.py after transfering working script to new cog

时间:2018-05-28 18:40:50

标签: python json discord discord.py discord.py-rewrite

from discord.ext import commands
import discord
import json

d = {"warning1": []}


class Moderation:
def __init__(self, bot):
    self.bot = bot

async def on_ready(self):
    """Prints to the console that the test cog is working"""
    print("Ready in Moderation Cog.")

@commands.command()
async def warn(ctx, user: discord.Member=None):
    """Warns the user, writes the information to a json file and
    if they get warned a second time it kicks them from the server"""
    with open("test.json", "r") as fp:
        liste = json.load(fp)
    if str(user.id) in liste.get("warning1"):
        await ctx.send("User has already been warned once, banning user!")
        await user.kick()
    else:
        with open("test.json", "w") as fp:
            d["warning1"].append(str(user.id))
            json.dump(d, fp)
        await ctx.send("User has been warned")


def setup(bot):
    bot.add_cog(Moderation(bot))

It was working fully before I switched it over to a new cog, so something has broken there, I've also tried async def warn(self, ctx, user: discord.Member=None): instead of without the self, but that still gives the same error message.

Inside the json file looks like this right now:

{"warning1": ["227896738873212929"]}

0 个答案:

没有答案