小编kyb*_*ybt的帖子

TypeError:TextIOWrapper类型的对象不可JSON序列化

如果代码能够正常工作,那么每当有人在聊天中键入某些内容时,他们都会获得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)

python json discord python-3.7 discord.py

2
推荐指数
2
解决办法
9805
查看次数

标签 统计

discord ×1

discord.py ×1

json ×1

python ×1

python-3.7 ×1