Search code examples
pythondiscordbotsdiscord.py

Discord.Py Embed Command


I'm making a bot with all kinds of commands. One of those commands is supposed to be making embeds. Such as where you say the command, the title, and the description. But the bot can only take one word as the title, and one word as the description. I need help, my code is used below. (toob is the prefix)

@client.command()
async def makeEmbed(ctx, title: str, description : str):
  if not title:
    await ctx.channel.send("One or more values are missing. Command should look like 'toob makeEmbed (title), (description)'")
  elif not description:
    await ctx.channel.send("One or more values are missing. Command should look like 'toob makeEmbed (title), (description)'")

  
  embed = discord.Embed(title=title, description=description, color=0x72d345)
  await ctx.send(embed=embed)

Solution

  • Here's an idea:

    @client.command()
    async def make_embed(ctx, *, content: str):
        title, description = content.split('|')
        embed = discord.Embed(title=title, description=description, color=0x72d345)
        await ctx.send(embed=embed)
    

    to invoke → toob make_embed Some Title | Some description with a loooot of words

    The downside is that you´ll need to add a | in the message, here's another solution with wait_for():

    @client.command()
    async def make_embed(ctx):
        def check(message):
            return message.author == ctx.author and message.channel == ctx.channel
    
        await ctx.send('Waiting for a title')
        title = await client.wait_for('message', check=check)
      
        await ctx.send('Waiting for a description')
        desc = await client.wait_for('message', check=check)
    
        embed = discord.Embed(title=title.content, description=desc.content, color=0x72d345)
        await ctx.send(embed=embd)
    

    to invoke ↓

    >>> toob make_embed
    ... Waiting for a title
    >>> Some title here
    ... Waiting for a description
    >>> Some description here
    

    Or you can do what ThRnk suggested.

    Sources: