This is My inventory command sorry, I cant send the image cuz I don't have 10 reputations to do that, here is my code first see the image it will help you guys get a better understanding of what I am asking pardon if it sounds rude
@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}"))
SO I am making a bot like dank Memer For my discord Server, I am pretty sure you guys have seen the dank memer Inventory command, How beautiful their embed is and the use of emoting But as I have shown you guys an image, my inventory command is kinda messy and ugly and I am getting record but I want to value and count, how can I get them and how can I make embed like dank memer like the amount of space btw 1 item, emotes and everything I am new here so pardon if I asked something that I should not
CodePudding user response:
To the item_name
you'd have to do:
element.get("item_name", "no name")
see: https://magicstack.github.io/asyncpg/current/api/index.html?highlight=record#asyncpg.Record
If it does not find item_name
it will return the string "no name"
You created an Embed here:
embed=discord.Embed(title=f"{interaction.user.name}'s Inventory ", description=f"{lol}")
However that only has a title
and description
. If you want to put the item_name
and count
information into embed you do something like:
embed.add_field(name=element.get("item_name", "no name"), value=element.get("count", "NaN"))
see: https://discordpy.readthedocs.io/en/stable/api.html?highlight=embed#discord.Embed.add_field
so it looks something like:
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: Code looks really ugly but I'm just basing mine off yours. It is not recommended but I understand you are learning.