2

I'm just making discord bot with python3

@client.event
async def on_message(message):
    #if bot ignore
    if message.author.bot:
        return None
    
    if message.content.startswith('!meal'):
        with open('menu.json') as json_file:
            data = json.load(json_file)
        channel = message.channel
        await channel.send('This is meal info!')
        await channel.send(data())

but I got

UnicodeDecodeError: 'cp949' codec can't decode byte 0xeb in position 24: illegal multibyte sequence

this errors.. how can I open this json file automatically?

2 Answers2

4

You may need to specify an encoding when opening the JSON, like this:

with open('menu.json', encoding='utf-8') as json_file:

Where you substitute utf-8 with whatever encoding you saved menu.json with.

xavc
  • 1,245
  • 1
  • 8
  • 14
0

I got the same error because chardet told me that the encoding should be 'cp949', but it was clearly not. Tried 'utf8' but doesn't work but 'Windows-1252' does.