0
votes

I have say command that works fine, replying with a message I provide in it. However, I want to change the code to support custom embed body message as well.

Basically, my question is: How can I make my say command reply with message OR custom Embed body message?

My say command

@commands.command(name='say', aliases=['repeat', 'talk'])
    @commands.has_permissions(manage_messages=True)
    async def _say(self, ctx, *, message):
        await ctx.send(message, ctx)

What I want my command to be able to do is...

Example:

-say {embed=discord.Embed(title="Test", description="Embed Example")
embed.set_author(name="Author", url="https://authorlink.com", icon_url="https://authoricon.com")
embed.set_thumbnail(url="https://thumbnail.png")
embed.add_field(name="Field 1", value="Field test 1", inline=True)
embed.add_field(name="Field 2", value="Field test 2", inline=False)
embed.set_footer(text=ctx.guild.name)
await ctx.send(embed=embed)}

expected bot response

Does anyone know how to make the code to send custom embed body message as well? I understand Embed and how to form it. Now, I just want my command be able to say both custom embed and custom message. I hope it makes sense what my idea is.

  • Edit: This is what I got for embed (as separated command)

(This way I cannot customize the entire embed, but only the value of the field provided in the code. I'm looking for a way to make it fully custom, if possible, and merging it with one command only, for embed and normal message)_

@commands.command(name="sayembed")
    @commands.has_permissions(manage_messages=True)
    async def _saye(self, ctx, *, message):
        embedsay = discord.Embed(color=ctx.author.color, timestamp=ctx.message.created_at)
        embedsay.set_author(name="Message from:", icon_url=ctx.author.avatar_url)
        embedsay.add_field(name=ctx.message.author, value=str(message))
        embedsay.set_thumbnail(url=ctx.author.avatar_url)
        embedsay.set_footer(text=ctx.guild.name)
        await ctx.send(embed=embedsay)
3
Could you include some examples of how you would call your command to send an embed? If you were writing a command that just sent the embed, what would that look like?Patrick Haugh
Like I said, it's same command, I'm just looking for a way that -say command can send both kinds of message. If it's not possible, I guess I'd be satisfied with separate command for embed, probably as -sayembedor something.xscriptxdata
For now I do have an example command to send the embed, but the thing is, it can send only custom field value, not entire custom embed message (as custom footer, fields, embed info, etc.). I'll add an example of embed message into my post.xscriptxdata

3 Answers

0
votes

for your say command is fine, but if you want to add embed, you need a embed = discord.Embed() Example:

import datetime
import discord
from discord import Embed
from discord.ext import commands

client = commands.Bot(command_prefix='PREFIX')

@client.command()
async def embed(ctx):
    embed = discord.Embed(
        title='This is a title! you can customise this!',
        description='This is a description!',
        colour=discord.Color.green(),
        timestamp=datetime.datetime.now()

        ).add_field(
        name='This is non inlined field 1!',
        value='This is a value!',
        inline=False

        ).add_field(
        name='This is a non inlined field 2!',
        value='This is a value!',
        inline=False

        ).add_field(
        name='This is a inlined field 1!',
        value='This is a value!',
        inline=True

        ).add_field(
        name='This is a inlined field 2!',
        value='This is a value!',
        inline=True

        ).set_footer(
        text='This is a footer!',
        icon_url='https://cdn.discordapp.com/avatars/694446165197979670/eb946325b85f913abdec645d0c14b98a.webp?size=1024'

        ).set_image(
        url='https://cdn.discordapp.com/avatars/694446165197979670/eb946325b85f913abdec645d0c14b98a.webp?size=1024'

        ).set_thumbnail(
        url='https://cdn.discordapp.com/avatars/694446165197979670/eb946325b85f913abdec645d0c14b98a.webp?size=1024'
        )

    await ctx.send(embed=embed)

you can fully customize embed, but if you don't include title or a value on add_field it will raise a error (of course you can f string them).

Embed docs

if you want to sent a message to a spesific message you can do

@client.command()
async def say(ctx, member: discord.Member, *, message):
    embed = discord.Embed(
        title=message,
        description=f"From: {ctx.author}",
        colour=discord.Color.green()
        )

    await member.send(embed=embed)
0
votes

I know this has been solved, but unless the message changes for every parameter (e.g. kick command), you dont have to include it in the command itself, you can just use:

<varname> = discord.Embed(title=„title”, description=„description”, color=(use hex codes)
<varname>.add_field(basically the field, im on an iPhone rn and dont want to type it all out)
<varname>.set_footer, .set_thumbnail, etc.

async def say(ctx):
[TAB] ctx.send(embed=<varname>)
0
votes

you can use this code remember to split the title and description with / or the command won't work example command : !embed title/description

import discord
from discord.ext import commands
import datetime

bot = commands.bot(command_prefix=commands.when_mentioned_or("!"))

@bot.command()
async def embed(ctx, *, content: str):
   title, description= content.split('/')
   embed = discord.Embed(
   title=title,
   description=description,
   colour=discord.Color.green(),
   timestamp=datetime.datetime.now()

        
   )

   await ctx.send(embed=embed)

bot.run("your token here")