简体   繁体   中英

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)

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 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:

@client.command() async def test(ctx): e = discord.Embed( title="Title Of The Embed Here!", description="Description Of The Embed Here!", color=0xFF0000 #i added hex code of red u can add any like of blue ) await ctx.send(embed=e)

embed = discord.Embed(title="Your title here", discription="Your discripion", colour=Your color here) embed.add_field(name="name="name", value="your value here")

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM