如果代码能够正常工作,那么每当有人在聊天中键入某些内容时,他们都会获得5点经验,并将这些信息保存到.json文件中,但是,当有人在聊天中键入某些内容时,会发生此错误。
on_message users = json.dumps(f)
TypeError: Object of type TextIOWrapper is not JSON serializable
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码:
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import json
from json import dumps, loads, JSONEncoder, JSONDecoder
import os
client = commands.Bot(command_prefix='^')
os.chdir(r'C:\Users\quiny\Desktop\sauce')
@client.event
async def on_ready():
print ("Ready when you are xd")
print ("I am running on " + client.user.name)
print ("With the ID: " + client.user.id)
@client.event
async def on_member_join(member):
with open('users.json', 'r') as f:
users = …Run Code Online (Sandbox Code Playgroud)