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))
Он работал полностью до того, как я переключил его на новый Cog, поэтому что-то там сломалось, я также попробовал async def warn(self, ctx, user: discord.Member=None):
вместо self
, но это все равно выдает то же сообщение об ошибке.
Внутри json-файл выглядит прямо сейчас:
{"warning1": ["227896738873212929"]}