'Sending DM with embeds using discord.py

I have tried many things but I can't get discord.py to send a message with embeds. But I have gotten it to send a normal message when a command is typed using this code.

@client.event
async def on_message(message):
  msg = message.content

  if msg.startswith('$helpme'):
    await message.author.send("this text would be sent via dm, but with no embeds...")

It would be a help menu which the bot would the dm the user when $helpme is typed. Problem is I can't get it to send this embed code.

  embed=discord.Embed(title="👍 Help", description="I am here to help!", color=0x0000ff)
  embed.set_author(name="Meerdus", icon_url="https://cdn.discordapp.com/attachments/834885490451808286/939646209092616312/M.png")
  embed.add_field(name="$helpme", value="Shows this menu!", inline=False)
  embed.add_field(name="$kick", value="Kick a member if you have Administrator permissions!", inline=False)
  embed.add_field(name="$ban", value="Ban a member if you have Administrator permissions!", inline=False)
  embed.add_field(name="$unban", value="Unban a member if you have Administrator permissions.", inline=False)
  embed.add_field(name="$lock", value="Lock a channel if you have the permission to manage channels!", inline=False)
  embed.add_field(name="$meme", value="Display a random clean meme! :)", inline=False)
  embed.add_field(name="$doggo", value="Show a random dog picture and dog fact!", inline=False)
  embed.add_field(name="$kitty", value="Show a random cat picture and cat fact!", inline=False)
  embed.add_field(name="$birdy", value="Show a random bird picture and bird fact!", inline=False)
  embed.add_field(name="$randomnum", value="Display a random number between 1 and 100!", inline=False)
  embed.add_field(name="$tictactoe", value="Play tictactoe with two people by specifing <command> <yourusername> <secondplayersusername>", inline=False)
  embed.add_field(name="DONT ACTUALLY ENTER THE <>", value="You have to enter the things said inside them.", inline=False)
  await ctx.send(embed=embed)


Solution 1:[1]

I believe the issue is it needs to be await message.author.send() not await ctx.send() since in the code snippet that works it is in the on_message() event listener. ctx.send() is how you would do it in a Bot command. The syntaxation is completely fine.

For example in my own discord bot you can see I send the help embed inside a cog the exact same way as the second snippet which is completely functional.

Solution 2:[2]

Since you aren't using a bot command, you don't use ctx. This is also mainly because you haven't passed (told the function about) ctx. Instead, use message.author.send().

See the examples below:

message.author.send(embed=embed) # Send to the author
message.channel.send(embed=embed) # Send to the channel

Solution 3:[3]

Instead of ctx.send use ctx.author.send

  embed=discord.Embed(title="? Help", description="I am here to help!", color=0x0000ff)
  embed.set_author(name="Meerdus", icon_url="https://cdn.discordapp.com/attachments/834885490451808286/939646209092616312/M.png")
  embed.add_field(name="$helpme", value="Shows this menu!", inline=False)
  embed.add_field(name="$kick", value="Kick a member if you have Administrator permissions!", inline=False)
  embed.add_field(name="$ban", value="Ban a member if you have Administrator permissions!", inline=False)
  embed.add_field(name="$unban", value="Unban a member if you have Administrator permissions.", inline=False)
  embed.add_field(name="$lock", value="Lock a channel if you have the permission to manage channels!", inline=False)
  embed.add_field(name="$meme", value="Display a random clean meme! :)", inline=False)
  embed.add_field(name="$doggo", value="Show a random dog picture and dog fact!", inline=False)
  embed.add_field(name="$kitty", value="Show a random cat picture and cat fact!", inline=False)
  embed.add_field(name="$birdy", value="Show a random bird picture and bird fact!", inline=False)
  embed.add_field(name="$randomnum", value="Display a random number between 1 and 100!", inline=False)
  embed.add_field(name="$tictactoe", value="Play tictactoe with two people by specifing <command> <yourusername> <secondplayersusername>", inline=False)
  embed.add_field(name="DONT ACTUALLY ENTER THE <>", value="You have to enter the things said inside them.", inline=False)
  await ctx.author.send(embed=embed)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 leftomash
Solution 2 Trent112232
Solution 3 Shashankh_