更新嵌入消息不起作用 - discord.py

时间:2021-02-26 11:37:49

标签: python json discord discord.py

我正在我的 Discord 机器人中制作一个非常详细的 RPG 系统。现在,我正在创建一个塔命令,让您可以在塔的各个阶段进行游戏并与不同类型的敌人作战。问题是我不知道为什么编辑嵌入的消息不起作用,它应该根据敌人击中你的程度来更新你和敌人的 HP。它适用于普通消息,它更新敌人给你的 DMG,但不适用于嵌入消息,有什么想法吗?我真的希望有一些解决方案,因为我不想把它完全改成只有简单的消息,那看起来不太好。

这是在不和谐聊天中的样子,嵌入的消息不会更新巨魔或玩家的 HP,它仅适用于嵌入的普通消息。

enter image description here

代码:(唯一对您来说应该重要的代码行从嵌入消息开始,但我包含了整个代码只是为了更具体)。

# Tower
@bot.command()
@commands.cooldown(1, 100.0, commands.BucketType.user)
async def tower(msg):
    await open_rpg(msg.author)
    user = msg.author
    users = await rpg_data()

    question= await msg.send(msg.author.mention + " Do you really wish to enter the tower? `yes` `no`")
    def checkyn(message):
        return message.content in ["yes", "no"]

    while True:
        answer = await bot.wait_for("message", check=checkyn)
        if answer.author.id == msg.author.id:
            break

    if answer.content == "no":
        await answer.delete()
        await msg.message.delete()
        await question.delete()
        return

    names= ["nothing","Troll","Lion","Fish"......]

    battle = users[str(user.id)]["battle-active"]
    if battle == 1:
        await msg.send(msg.author.mention + " You are currently fighting!")
        tower.reset_cooldown(msg)
        return

    users[str(msg.author.id)]["battle-active"] += 1
    with open("rpg.json", "w") as f:
        json.dump(users, f)

    coins = users[str(user.id)]["coins"]
    mages = users[str(user.id)]["mages"]
    guardians = users[str(user.id)]["guardians"]
    hunters = users[str(user.id)]["hunters"]
    defense = users[str(user.id)]["defense"]
    power = users[str(user.id)]["power"]
    rpoints = users[str(user.id)]["rpoints"]
    hunger = users[str(user.id)]["hunger"]
    armor = users[str(user.id)]["armor"]
    shield = users[str(user.id)]["shield"]
    sword = users[str(user.id)]["sword"]
    sword_durability = users[str(user.id)]["sword-durability"]
    shield_durability = users[str(user.id)]["shield-durability"]
    armor_durability = users[str(user.id)]["armor-durability"]
    shield_defense = users[str(user.id)]["shield-defense"]
    sword_DMG = users[str(user.id)]["sword-DMG"]
    stage = users[str(user.id)]["stage"]

    defense_percent = (1 + (guardians / 10)) + (shield / 2) - (((shield_durability * -1) + 100) / 10) - (hunger)
    power_percent = (1 + (mages / 10)) + (sword / 2) - (((sword_durability * -1) + 100) / 10) - (hunger)
    luck_percent = (1 + (hunters / 10)) + (armor / 2) - (((armor_durability * -1) + 100) / 10) - (hunger)

    if defense_percent <= 0:
        defense_percent = 0
    if power_percent <= 0:
        defense_percent = 0
    if luck_percent <= 0:
        defense_percent = 0

    defense = defense_percent * defense + shield_defense
    power = power_percent * power + sword_DMG
    defense = round(defense)
    power = round(power)

    hp = 100
    hp = hp + defense

    hp_enemy = 100
    power_enemy = 50

    e = discord.Embed(title=names[stage] + " - " + str(stage) + ". stage",color=3447003)
    e.set_thumbnail(url="https://i.imgur.com/Fu0Ra1W.png")
    e.add_field(name="Your statistics", value="```" + str(hp) + " HP " + str(power) + " DMG ```", inline=False)
    e.add_field(name="Enemy statistics", value="```" + str(hp_enemy) + " HP " + str(power_enemy) + " DMG ```", inline=False)
    e.set_footer(text="g tutorial tower")
    message_embed = await msg.send(embed=e)

    def checkyn(message):
        return message.content in ["a", "h", "p", "d"]

    enemy_attack = random.randint(0, power_enemy)
    hp -= enemy_attack
    message_enemy_attack = await msg.send("Enemy hit you for " + str(enemy_attack) + " DMG.")
    await message_embed.edit(embed=e)
    if hp <= 0:
        await msg.send(msg.author.mention + "** Battle has ended.** You have lost.")
        users[str(msg.author.id)]["battle-active"] -= 1
        with open("rpg.json", "w") as f:
            json.dump(users, f)
        return
    while True:
        answer = await bot.wait_for("message", check=checkyn)
        while True:
            if answer.author.id == msg.author.id:
                break
        if answer.content == "a":
            player_attack = random.randint(0, power)
            hp_enemy -= player_attack
            await answer.delete()
            await message_embed.edit(embed=e)
            if hp_enemy <= 0:
                await msg.send(msg.author.mention + "** Battle has ended.** You have won and defeated the stage.")
                users[str(msg.author.id)]["battle-active"] -= 1
                with open("rpg.json", "w") as f:
                    json.dump(users, f)
                return
        enemy_attack = random.randint(0, power_enemy)
        hp -= enemy_attack
        await message_enemy_attack.edit(content="Enemy hit you for " + str(enemy_attack) + " DMG.")
        await message_embed.edit(embed=e)
        if hp <= 0:
            await msg.send(msg.author.mention + "** Battle has ended.** You have lost.")
            users[str(msg.author.id)]["battle-active"] -= 1
            with open("rpg.json", "w") as f:
                json.dump(users, f)
            return

0 个答案:

没有答案