简体   繁体   English

Discord中的“期望属性名称用双引号引起来”

[英]“Expecting property name enclosed in double quotes” in Discord

I am coding a discord bot to use with my friends and I am getting a weird message on one of my cogs. 我正在编写一个与我的朋友一起使用的不和谐机器人,并且在我的一位嵌齿轮上收到一条奇怪的消息。 The code works perfect on one cog and doesn't at all on the other. 该代码在一个嵌齿轮上完美运行,而在另一嵌齿上则完全不起作用。

I've tried rewriting the command and trying to get the data in a different way to no avail. 我尝试重写命令,并尝试以无济于事的其他方式获取数据。

import discord
import json
import os
from discord.ext import commands

class Inventory(commands.Cog):

    def __init__(self, client):
        self.client = client

    @commands.command(aliases=['iindex', 'ii'])
    async def itemindex(self, ctx, arg1='nd', arg2='nd'):
        await ctx.channel.purge(limit=1)
        if arg1 == 'nd':
            embed=discord.Embed(title="insert title", description='insert text', color=0x02a5fd)
            embed.set_footer(text="insert footer")
            await ctx.send(embed=embed)

        if arg1 == 'standard':

            if arg2 == 'nd':
                _n = 1
                _a = 0
                embed=discord.Embed(title="insert title", color=0x02a5fd)
                with open('database.json', 'r') as f:
                    data = json.load(f) #error on this line

                while _a < 20:
                    for item in data['items']['standard']:
                        if data['items']['standard'][item]['itemid'] == _n:
                            name = data['items']['standard'][item]['name']
                            embed.add_field(name=f'{name}', value=f'ID: {_n}', inline=False)
                            _n += 1
                            _a += 1

                embed.set_footer(text="insert footer")
                await ctx.send(embed=embed)

def setup(client):
    client.add_cog(Inventory(client))

What it should be doing is loading the file and looping through the items in the key, but it won't even get to that point. 它应该做的是加载文件并遍历密钥中的所有项目,但到那为止都不会。 Instead, it gives me this error: 相反,它给了我这个错误:

Ignoring exception in command itemindex:
Traceback (most recent call last):
  File "C:\Users\stars\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\stars\Documents\Projects\Discord\Neximator\cogs\inventory.py", line 30, in itemindex
    data = json.load(f)
  File "C:\Users\stars\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Users\stars\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Users\stars\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\stars\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 43 column 5 (char 1218)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\stars\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 859, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\stars\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 725, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\stars\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 88, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: JSONDecodeError: Expecting property name enclosed in double quotes: line 43 column 5 (char 1218)

Am I doing something wrong or is this a bug? 我是在做错什么还是错误?

Edit: I realize now that this could be a json error because I am pretty new to JSON and don't really know all of the rules. 编辑:我现在意识到这可能是一个json错误,因为我对JSON很陌生,并且并不真正了解所有规则。 Here is the database.json file I'm using: 这是我正在使用的database.json文件:

{
  "nicknames": {
    "discordname": "nickname",
  },
  "items": {
    "standard": {
      "slimeball": {
        "name": "Slimeball",
        "description": "Ball of sticky, viscous slime dropped by... well... slimes.",
        "rarity": "D",
        "itemid": 1
      }
    },
    "weapon": {
      "wooden_dagger": {
        "name": "Wooden Dagger",
        "description": "A stick with an edge lazily carved into it.",
        "type": "sword",
        "damage": "1d3",
        "accuracy": "1d20",
        "weaponid": 1
      },
      "wooden_gaunlets": {
        "name": "Wooden Gaunlets",
        "description": "Two logs with holes for your hands.  There are several designs lazily cut into it.",
        "type": "melee",
        "damage": "2d2",
        "accuracy": "2d10",
        "weaponid": 2
      },
      "wooden_bow": {
        "name": "Wooden Bow",
        "description": "A stick with a thin strand of elastic threaded through the ends creating an arch.",
        "type": "ranged",
        "damage": "1d4",
        "accuracy": "1d25",
        "weaponid": 3
      },
    }
  },
  "enemies": {
  }
}

This is happening because f is not valid JSON. 发生这种情况是因为f是无效的JSON。

It gives you a pretty clear error as to why. 它为您提供了一个非常清楚的错误原因。 Expecting property name enclosed in double quotes

Without seeing your json file I can't really say more. 没有看到您的json文件,我真的不能说更多。 But I am assuming database.json is not valid JSON. 但是我假设database.json是无效的JSON。 My guess is that you are using single quotes on your keys. 我的猜测是您在键上使用单引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Oandapy:期望属性名称用双引号引起来 - Oandapy: Expecting property name enclosed in double quotes JSONDecodeError:期望用双引号括起来的属性名称 - JSONDecodeError: Expecting property name enclosed in double quotes 期望用双引号括起来的属性名称 - Expecting property name enclosed in double quotes Python - JSONDecodeError:需要用双引号括起来的属性名称 - Python - JSONDecodeError: Expecting property name enclosed in double quotes 错误:“期望属性名称用双引号引起来:第2行第1列(字符2)” - Error: “Expecting property name enclosed in double quotes: line 2 column 1 (char 2)” ValueError:期望属性名称用双引号引起来:第1行第2列(字符1) - ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) JSONDecodeError:期望用双引号括起来的属性名称:第 1 行第 3 列(字符 2) - JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2) Python:JSONDecodeError:期望用双引号括起来的属性名称 - Python: JSONDecodeError: Expecting property name enclosed in double quotes Python/Json:期望用双引号引起来的属性名称 - Python/Json:Expecting property name enclosed in double quotes scrapyd异常期望属性名称用双引号引起来 - scrapyd Exception Expecting property name enclosed in double quotes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM