晚上好。
我有一些Twitter链接发送到我的一个Discord频道,我想阅读完整的信息.嵌入的URL。
例子
@bot.event
async def on_message(message):
if message.author == bot.user:
return
print(f'{message.embeds[0]})
输出。
<discord.embeds.Embed object at 0x1083f22d0>
下面是一个会通过的URL的例子。 https:/twitter.comFortniteStatusstatus1255881010400632832。
我想把链接的所有字段都打印出来,这样我就可以推断出链接中的信息正文。 例如,我可以这样找到图片***强文字***的内容。
@bot.event
async def on_message(message):
if message.author == bot.user:
return
print(f'{message.embeds[0].image})
下面是输出结果
EmbedProxy(width=1920, url='https://pbs.twimg.com/media/EW3ItMcXsAAtJqs.jpg:large', proxy_url='https://images-ext-1.discordapp.net/external/07ehAt_tC9hRC9peWhXgLLK6HkBlvoWuc-_jjVb-3Js/https/pbs.twimg.com/media/EW3ItMcXsAAtJqs.jpg%3Alarge', height=1080)
从这张图片中,我想得到的是嵌入的主体,而不是图像。
我以为可以通过打印出embed来实现,但看起来我得到的是一个内存参考? 有什么想法?
你可以将 Embed
词典和它的 to_dict
方法,然后打印出来。
from pprint import pprint
from discord.ext import commands
bot = commands.Bot("!")
@bot.event
async def on_message(message):
if message.embeds:
pprint(message.embeds[0].to_dict())
bot.run("token")
对于你的例子,这将打印
{'author': {'icon_url': 'https://pbs.twimg.com/profile_images/1182784466240135170/tTYzHFoe_bigger.jpg',
'name': 'Fortnite Status (@FortniteStatus)',
'proxy_icon_url': 'https://images-ext-1.discordapp.net/external/wF3vK-DmpMjN_SM_GIU9fRgqjVrtdyzw8xMIT883ScQ/https/pbs.twimg.com/profile_images/1182784466240135170/tTYzHFoe_bigger.jpg',
'url': 'https://twitter.com/FortniteStatus'},
'color': 1942002,
'description': 'Hey, everyone!\n'
'\n'
'We\'re aware that the "Throw Henchmen overboard at The Yacht" '
'Location Domination Challenge may not be tracking progress '
'properly and are working to resolve this.\n'
'\n'
"We'll update you all when this is resolved.",
'fields': [{'inline': True, 'name': 'Retweets', 'value': '258'},
{'inline': True, 'name': 'Likes', 'value': '4733'}],
'footer': {'icon_url': 'https://abs.twimg.com/icons/apple-touch-icon-192x192.png',
'proxy_icon_url': 'https://images-ext-1.discordapp.net/external/bXJWV2Y_F3XSra_kEqIYXAAsI3m1meckfLhYuWzxIfI/https/abs.twimg.com/icons/apple-touch-icon-192x192.png',
'text': 'Twitter'},
'image': {'height': 1080,
'proxy_url': 'https://images-ext-1.discordapp.net/external/07ehAt_tC9hRC9peWhXgLLK6HkBlvoWuc-_jjVb-3Js/https/pbs.twimg.com/media/EW3ItMcXsAAtJqs.jpg%3Alarge',
'url': 'https://pbs.twimg.com/media/EW3ItMcXsAAtJqs.jpg:large',
'width': 1920},
'type': 'rich',
'url': 'https://twitter.com/FortniteStatus/status/1255881010400632832'}