How can I send an embed via my Discord bot, w/python?
Solution 1
To get it to work I changed your send_message line to
await message.channel.send(embed=embed)
Here is a full example bit of code to show how it all fits:
@client.event
async def on_message(message):
if message.content.startswith('!hello'):
embedVar = discord.Embed(title="Title", description="Desc", color=0x00ff00)
embedVar.add_field(name="Field1", value="hi", inline=False)
embedVar.add_field(name="Field2", value="hi2", inline=False)
await message.channel.send(embed=embedVar)
I used the discord.py docs to help find this. https://discordpy.readthedocs.io/en/latest/api.html#discord.TextChannel.send for the layout of the send method.
https://discordpy.readthedocs.io/en/latest/api.html#embed for the Embed class.
Before version 1.0: If you're using a version before 1.0, use the method await client.send_message(message.channel, embed=embed)
instead.
Solution 2
When executing this code, I get the error that 'Embed' is not a valid member of the module 'discord'. All websites, show me this code, and I have no idea of any other way to send a embed.
This means you're out of date. Use pip
to update your version of the library.
pip install --upgrade discord.py
Solution 3
@bot.command()
async def displayembed(ctx):
embed = discord.Embed(title="Your title here", description="Your desc here") #,color=Hex code
embed.add_field(name="Name", value="you can make as much as fields you like to")
embed.set_footer(name="footer") #if you like to
await ctx.send(embed=embed)
Solution 4
how about put @client.event
instead of the @bot.command()
it fixed everything when I put @client.event... @bot.command() does not work you can type
@client.event
async def displayembed(ctx):
embed = discord.Embed(title="Your title here", description="Your desc here") #,color=Hex code
embed.add_field(name="Name", value="you can make as much as fields you like to")
embed.set_footer(name="footer") #if you like to
await ctx.send(embed=embed)
Related videos on Youtube
Norberto A.
Hello! I'm Norberto! I'm a 19 year old self taught programmer from Portugal! I currently code LUA, JavaScript. I'm learning Python (again) & Java. I'm also working in web development projects.
Updated on July 09, 2022Comments
-
Norberto A. almost 2 years
I've been working a new Discord bot.
I've learnt a few stuff,and, now, I'd like to make the things a little more custom.
I've been trying to make the bot send embeds, instead, of a common message.
embed=discord.Embed(title="Tile", description="Desc", color=0x00ff00) embed.add_field(name="Fiel1", value="hi", inline=False) embed.add_field(name="Field2", value="hi2", inline=False) await self.bot.say(embed=embed)
When executing this code, I get the error that 'Embed' is not a valid member of the module 'discord'. All websites, show me this code, and I have no idea of any other way to send a embed.
-
Joel almost 3 yearsThe discord.py error handling ignores errors like these, since in production a single error could cuase your whole bot to break. Hence, i recommend putting a try except block inside the function everytime you are testing, it will help alot in terms of understanding the error
-
-
Norberto A. almost 7 yearsSomehow now, it gives me a new error. "expected an intend block", and the arrow shows the error in the 'd' of the "embed = "
-
Tim almost 7 yearsMake sure you haven't by accident indented something. Check the indentation of the if statement and that line.
-
Norberto A. almost 7 yearsI did, and everything's right. It keeps saying that somehow.
-
Tim almost 7 yearsI'm not sure then. Sorry. Try asking in this discord server discord.gg/discord-api or you could try reporting it as a issue on the github. Also someone else seems to of had this issue so maybe monitor that post as well stackoverflow.com/questions/44474955/….
-
Norberto A. almost 7 yearsIt says that there's a syntax error in the install bit.
-
khazhyk almost 7 yearsWhere does it say you're getting a syntax error? You run this command in the command line
-
Norberto A. almost 7 yearsI had done this in the bot's script, lmao. Anyways, I tried run this in the cmds thing, and it didn't work. Let me send print. prntscr.com/fvjbff What am I doing wrong?
-
Person over 5 years@Norby I'm a little late, but you haven't added
pip
topath
-
knee-cola about 4 yearsmaybe you should point out what was wrong with the code posted in the question
-
Wise Man almost 4 yearsYou should pick a different name for variable "embed", not sure if it can cause errors, bat anyways,
embed=embed
is not that clear.. -
Tim almost 4 years@WiseMan I've changed it to
embedVar
. Do you think that name is suitably clear or have any other suggestions? -
Westlenando over 3 yearschange
self.bot.say
toctx.send