在discord.py中打印嵌入 [英] print embeds in discord.py
问题描述
这是对 discord.py-blank-messages的后续问题?
这是我的代码:
@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
我想知道这是因为该机器人正在发送嵌入内容,并且 log
无法打印嵌入。有没有办法将嵌入内容(通过将其转换为纯文本)打印到控制台上?
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?
推荐答案
使用 .embeds
属性获取邮件中的嵌入列表。这将返回 Embed
对象的列表,然后您可以访问这些对象的单个描述,标题,字段等。
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)
< hr>
参考文献:
-
Message.embeds
-
discord.Embed
-找到嵌入的属性此处。
Message.embeds
discord.Embed
- Find the embeds' attributes here.
这篇关于在discord.py中打印嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!