How does one link commands in discord.py?

56 Views Asked by At

How would I go about linking commands in my discord.py bot? I’ve seen it done in Dankmemer embeds but I wasn’t sure if it’s possible to replicate it in discord.py or how to replicate it in any language.enter image description here

I tried just putting the command as it would be typed by a user into the message but (as expected) it didn’t work

1

There are 1 best solutions below

0
On

You can use the fetch function to achieve this.

Code:

@bot.tree.command(name="linktree")
async def linktree(interaction:discord.Interaction):
    cmd = await bot.tree.fetch_commands()
    embed=discord.Embed(title="Test",description="description",color=discord.Colour.green())
    embed.add_field(name=cmd[0].mention,value=f"└{cmd[0].description}")
    await interaction.response.send_message(embed=embed,ephemeral=True)

The "how it works" part:

  • create a list variable, get the slash commands with the await bot.tree.fetch_commands() function

  • create an embed

  • add fields to the embed: name = cmd[x].mention, value=f"└{cmd[x].description}" where x is the index of your listitem

  • send the embed