Reputation: 312
This is a follow-up question to discord.py-blank-messages?
This is my code:
@bot.event
async def on_message(message):
log = "\n[MESSAGE] [{0}] <{1}>\n----\n{2}\n----".format(message.guild, message.author, message.content)
print(log)
Which will print out something like this:
[MESSAGE] [Example_Server] <User#0001>
----
Lorem Ipsum
----
However, when embeds from bots are sent, this is the output:
[MESSAGE] [Example_Server] <Open Bump#1081>
----
----
I want to print the message that the bot sent in plain-text.
I have heard that this is because the bot is sending embeds, and that the log
cannot print embeds. Is there a way to print embeds (by converting them into plain text) to the console?
Upvotes: 2
Views: 2472
Reputation: 6944
You can get a list of embeds in a message with the .embeds
attribute. This returns a list of Embed
objects, which you're then able to access the individual description, title, fields etc.
Edit this as you wish, but the example just prints the main description:
@bot.event
async def on_message(message):
embed = ""
if len(message.embeds) != 0:
embed = message.embeds[0].description
log = "\n[MESSAGE] [{0.guild}] <{0.author}>\n-----\n{0.content}{1}\n-----".format(message, embed)
print(log)
References:
Message.embeds
discord.Embed
- Find the embeds' attributes here.Upvotes: 3