
這是我的庫存命令 抱歉,我無法發送影像,因為我沒有 10 名聲望這樣做,這是我的代碼首先查看影像它將幫助你們更好地理解我請求的內容,如果聽起來很抱歉粗魯的
@app_commands.command(name="inventory", description="check you inventory")
@app_commands.guild_only()
async def inventory(self, interaction: discord.Interaction) -> None:
await interaction.response.defer(ephemeral=False, thinking=True)
author = interaction.user.id
lol = await self.bot.db.fetch("SELECT item_info.item_name,user_inventory.count FROM user_inventory INNER JOIN item_info USING(item_id) WHERE user_inventory.user_id = $1",author)
await interaction.followup.send(embed=discord.Embed(title=f"{interaction.user.name}'s Inventory ", description=f"{lol}"))
所以我正在為我的不和諧服務器制作一個像 dank Memer 這樣的機器人,我很確定你們已經看到了 dank memer Inventory 命令,他們的嵌入多么漂亮以及如何使用 emoting 但正如我向你們展示的那樣,我的庫存命令有點凌亂和丑陋,我正在記錄,但我想重視和計數,我怎樣才能得到它們,我怎樣才能像 dank memer 那樣嵌入,比如空間量 btw 1 專案,表情和我在這里的一切都是新的所以請原諒我問了一些我不應該問的問題
uj5u.com熱心網友回復:

你item_name必須這樣做:
element.get("item_name", "no name")
見:https
://magicstack.github.io/asyncpg/current/api/index.html?highlight=record#asyncpg.Record
如果沒有找到item_name它會回傳字串"no name"
你在這里創建了一個嵌入:
embed=discord.Embed(title=f"{interaction.user.name}'s Inventory ", description=f"{lol}")
但是,只有一個titleand description。如果要將item_name和count資訊放入嵌入中,請執行以下操作:
embed.add_field(name=element.get("item_name", "no name"), value=element.get("count", "NaN"))
見:https ://discordpy.readthedocs.io/en/stable/api.html?highlight=embed#discord.Embed.add_field
所以它看起來像:
async def inventory(self, interaction: discord.Interaction) -> None:
await interaction.response.defer(ephemeral=False, thinking=True)
author = interaction.user.id
lol = await self.bot.db.fetch("SELECT item_info.item_name,user_inventory.count FROM user_inventory INNER JOIN item_info USING(item_id) WHERE user_inventory.user_id = $1",author)
embed=discord.Embed(title=f"{interaction.user.name}'s Inventory ", description="")
for element in lol:
embed.add_field(name=element.get("item_name", "no name"), value=element.get("count", "NaN"))
await interaction.followup.send(embed=embed)
PS:代碼看起來真的很丑,但我只是基于你的。不推薦,但我知道你正在學習。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/478871.html
