[英]Discord.py v1.7.3: Retrieving every embed from a channel and 'randomly' picking one to send as a message
What I'm trying to do: I am attempting to create a command that searches the history of a specific discord channel, creates an index of every embed in it, and then 'randomly' selects one.我想做什么:我正在尝试创建一个命令来搜索特定 discord 频道的历史记录,为其中的每个嵌入创建一个索引,然后“随机”选择一个。 Once it had done so, I intended it to forward the description of the embed so that the content of the embed was available in the channel the command was called in.
一旦它这样做了,我打算它转发嵌入的描述,以便嵌入的内容在调用命令的频道中可用。
Problem: It somewhat 'works' in that it retrieves embeds within the channel specified and forwards it to the channel called in, but I specifically wanted to get the embed descriptions instead of this: <Message id=id channel=<TextChannel id=id name='general' position=0 nsfw=False news=False category_id=id> type=<MessageType.default: 0> author=<User id=id name='name' discriminator='id' bot=False> flags=<MessageFlags value=0>>
问题:它有点“有效”,因为它检索指定通道内的嵌入并将其转发到调用的通道,但我特别想获取嵌入描述而不是这个:
<Message id=id channel=<TextChannel id=id name='general' position=0 nsfw=False news=False category_id=id> type=<MessageType.default: 0> author=<User id=id name='name' discriminator='id' bot=False> flags=<MessageFlags value=0>>
Originally, I had intended to actually include any attachments within the embed as well, but I couldn't even get the description alone so I quickly gave up on that until I could at least figure this out with my meager knowledge.最初,我实际上也打算在嵌入中包含任何附件,但我什至无法单独获得描述,所以我很快就放弃了,直到我至少可以用我微薄的知识弄清楚这一点。 Unfortunately I'm at a complete loss at what to do at this point.
不幸的是,此时我完全不知道该怎么做。
@commands.command(name="emb", brief="Rolls for HoF entries.", case_insensitive=True)
async def get_embeds(self, ctx):
channel = self.bot.get_channel(int(503998241193328672))
all_messages = await ctx.channel.history(limit=500).flatten()
for channel in ctx.guild.text_channels:
async for message in channel.history(limit=500):
all_messages.append(message.embeds)
message_to_send = random.choice(all_messages)
await ctx.send(message_to_send)
await ctx.send('Here you go {}'.format(ctx.author.mention))
You have just got the Message object. Ironically what you don't want is what you need to get the embed description.您刚刚收到消息 object。具有讽刺意味的是,您不想要的是获取嵌入描述所需的内容。 Access the description like so:
message_to_send.embeds[0].description
像这样访问描述:
message_to_send.embeds[0].description
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.