【问题标题】:Economy Object Doesnt Have An Attribute ctx经济对象没有属性 ctx
【发布时间】:2021-08-24 09:37:34
【问题描述】:

我正在制作经济齿轮,但我不断收到错误消息“经济对象没有属性 ctx”

这是我的命令代码

    @commands.command(name="bet", aliases=["be", "b"], brief="You bet for honeycomb", description="If you lose you give honeycomb, if you win you get honeycomb")
    async def _bet(self, ctx, amount : int = 5):
        with open("data/eco.json", "r") as dataRead:
            with open("data/eco.json", "r") as dataRead:
                cance = [True, False]
                random_chance = random.choice(cance)
                dataReadJSON = json.load(dataRead)
                if random_chance:
                    dataReadJSON[str(self.ctx.author.id)] += int(amount*2)
                    embed = discord.Embed(title="Bet", description=f"You bet and won <:honeycomb0:879275123486633984>{amount*2}", color=0xffff00)
                
                elif not random_chance:
                    dataReadJSON[str(self.ctx.author.id)] -= int(amount)
                    embed = discord.Embed(title="Bet", description=f"You bet and lost <:honeycomb0:879275123486633984>{amount}", color=0xff0000)

            with open("data/eco.json", "w") as dataWrite:
                json.dump(dataReadJSON, dataWrite)
            
            await ctx.send(embed=embed)

【问题讨论】:

  • 错误在第 9 行

标签: discord discord.py


【解决方案1】:

修复

我在测试时发现了这个修复,所以要修复它,你必须删除每个 ctx 中的 self 只有在你做客户端而不是 CTX 时才使用 SELF

例子:

@commands.command()
async def ping(self, ctx):
     await ctx.send("Pong! {int(self.client.latency*1000)}ms.")

【讨论】:

    猜你喜欢
    • 2022-10-03
    • 2019-06-14
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2021-06-15
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多