命令“guild create”TypeError中的Python错误:列表索引必须是整数或片,而不是s

2024-10-02 22:33:20 发布

您现在位置:Python中文网/ 问答频道 /正文

@guild.command(pass_context=True)
    async def create(self, ctx, name: str):
        """Create a guild for 70,000 gold."""
        user = ctx.message.author
        if user.id not in dev_list:
            await self.bot.say(":no_entry: This command is under constrction.")
            return
        guildmake = 0
        guildhash = random.randint(1000, 9999)
        userinfo = fileIO("data/alcher/users/{}/info.json".format(user.id), "load")
        userguild = fileIO("data/alcher/guilds/guilds.json", "load")
        if userinfo["gold"] >= 0:
            if user.id not in userguild:
                userguild[user.id] = [name, guildhash]
                userinfo["gold"] = userinfo["gold"] - guildmake
                fileIO("data/alcher/guilds/guilds.json", "save", userguild)

给我这个:

Error in command 'guild create' - TypeError: list indices must be integers or slices, not str

userguild[user.id]=[name,guildhash]<;这给了我一个错误。它告诉我我不能用绳子

有人能帮帮我吗


Tags: nameiniddataifnotcommandfileio