简体   繁体   中英

How to send embed with discord.py

I want to send embed message to a discord channel but in this way it doesn't work, did you have any idea?

@bot.command(
    name="my_first_command",
    description="This is the first command I made!",
    scope=[GUILD_ID],
)
async def my_first_command(ctx):
embed1 = discord.Embed(
        title=mob['name'],
        colour=0xE5E242,
        url=mob['url'],
        description="Famille: " + mob['type'],
    )
    embed1.set_image(url=mob['imgUrl'])
    embed1.add_field(name="Caractéristiques", value=stats, inline=False)

    await ctx.send(embed = embed1)

I got:

Task exception was never retrieved
future: <Task finished name='Task-13' coro=<my_first_command() done, defined at bot.py:18> exception=TypeError("send() got an unexpected keyword argument 'embed'")>
Traceback (most recent call last):
  File "bot.py", line 40, in my_first_command
    await ctx.send(embed = embed1)
  File "/home/user/.local/lib/python3.8/site-packages/interactions/client/context.py", line 445, in send
    payload = await super().send(content, **kwargs)
TypeError: send() got an unexpected keyword argument 'embed'

Try to specify only the embed, then Python has to find out for itself which parameter it fits to. So try that:

@bot.command(
    name="my_first_command",
    description="This is the first command I made!",
    scope=[GUILD_ID],
)
async def my_first_command(ctx):
embed1 = discord.Embed(
        title=mob['name'],
        colour=0xE5E242,
        url=mob['url'],
        description="Famille: " + mob['type'],
    )
    embed1.set_image(url=mob['imgUrl'])
    embed1.add_field(name="Caractéristiques", value=stats, inline=False)

    await ctx.send(embed1)

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