-1

so I asked for help in the replit server and they all started yelling at me bc i havent messed with json files to much

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'read'

thats the error i was given

heres the code they gave me

async def listblacklist(ctx):
    d = json.load('muted.json')
    ids = list(d.keys())
  • 1
    Does this answer your question? [AttributeError("'str' object has no attribute 'read'")](https://stackoverflow.com/questions/11174024/attributeerrorstr-object-has-no-attribute-read) – TheFungusAmongUs Jun 20 '22 at 13:48

1 Answers1

-1

Easy as this :

async def listblacklist(ctx):
    d = json.load(open("muted.json","r",encoding="utf-8"))
    ids = list(d.keys())

Hope this helps .

  • can you explain why this fixes the issue, so that anyone who comes to read this later will be able to tell if it will help them? – Esther Jun 20 '22 at 01:00
  • just another question, is there anyway to make it send them as mentions? – Monster png Jun 20 '22 at 01:03
  • Of course, json.load function requires a file object to read and scan it, not a string represents the file path . – Okba Elbahi Jun 20 '22 at 01:04
  • 1
    Please do not answer duplicate questions. Of course, it's the asker's duty to check for duplicates before asking the question, but as an answerer, you should also search the user's error before answering. If you find a duplicate, please flag the question as such. – TheFungusAmongUs Jun 20 '22 at 13:50
  • 1
    It is considered bad practice to inline open the file and then never close it. – Eric Jin Jun 20 '22 at 17:02