【发布时间】: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