【发布时间】:2021-09-01 22:11:13
【问题描述】:
我正在寻找一个可以在这里使用的简单解决方案:这是我的代码。
import discord
import json
from discord.ext import commands
print("Starting bot...")
TOKEN = ''
client = commands.Bot(command_prefix = '.')
@client.event
async def on_message(message):
embeds = message.embeds
for embed in embeds:
emb = str(embed.to_dict())
if 'owned' in emb:
owned = object('title')
print(owned)
print("Bot is ready!")
client.run(TOKEN)
(我确实有一个不和谐的机器人令牌,我将其删除以向大家展示)无论如何,我的目标是能够获取 emb,它来自脚本,如下所示:
{'footer': {'text': 'Item Type: Sellable'}, 'thumbnail': {'width': 75, 'url': 'https://cdn.discordapp.com/emojis/714980893999104051.png', 'proxy_url': 'https://images-ext-1.discordapp.net/external/c4teYBjoGAhxnygEZ5F2GlHWzReCIg_xEOX1PPtZdIQ/https/cdn.discordapp.com/emojis/714980893999104051.png', 'height': 75}, 'color': 15684432, 'type': 'rich', 'description': "This item's purpose is to be collected or sold. Nothing more, nothing less.\n\n**BUY** - Not able to be purchased\n**SELL** - ⏣ 1,680 (multiplier included)\n**TRADE** - 2k - 7k", 'title': '**Common Fish** (697 owned)'}
并且只能取最后一部分,即 697。我的主要问题是有时为 500,有时仅为 2,但我希望能够提取它并将其用作变量。请记住,线条的长度会有所不同。提前致谢!
【问题讨论】:
标签: python string discord discord.py