python - 文本检测 Discord.py PRAW
问题描述
@client.command(aliases=["h"]) # this is what the command will be in discord
async def letterh(ctx):
async with ctx.channel.typing():
memes_submissions = reddit.subreddit("theletterh").hot()
post_to_pick = random.randint(1, 10)
for i in range(0, post_to_pick):
submission = memes_submissions.__next__()
if len(submission.selftext) == 0:
embed = discord.Embed(
title=submission.title,
color=discord.Colour.purple()
)
embed.set_image(url=submission.url)
embed.add_field(name="Author", value="u/" + submission.author.name, )
embed.add_field(name="View Online", value=f"[Link]({submission.url})", )
embed.add_field(name="Subreddit", value="r/TheLetterH", )
else:
embed = discord.Embed(
title=submission.title,
description=submission.selftext,
color=discord.Colour.purple()
)
embed.add_field(name="Author", value="u/" + submission.author.name, )
embed.add_field(name="View Online", value=f"[Link]({submission.url})", )
embed.add_field(name="Subreddit", value="r/TheLetterH", )
await ctx.send(embed=embed)
这是我在检测到文本帖子时发布的代码。但事实并非如此。与其给我和错误,不如给我一个图像而不是文本。第一个 ( if len(submission.text == 0
) 如果检测到它应该发布一个文本帖子,另一个 ( else
) 如果它没有任何文本则应该发布一个普通的图像帖子。但是文字不起作用。没有一个错误,我需要你们的帮助!
解决方案
推荐阅读
- python - 使用多列值作为参数将函数应用于 pandas DataFrame 中的每一行
- java - 适用于 Java 1.6 的 Ant Java 任务
- java - 服务中存储类的同步和/或互斥
- r - R,没有默认值的参数丢失
- c++ - 我不知道为什么我的 while 循环没有给出预期的结果):
- c++ - Cmake 编译 Hydrogen 0.9.7 Beta1 时出错
- python - 是否可以在散景中使图像的特定颜色透明?
- amazon-web-services - 如何使用 AWS Cognito 限制自定义 api 访问
- excel - 工作表名称等于输入文本文件的名称
- java - DropWizard(使用 Jetty)使用 maven 在“org/eclipse/jetty/util/thread/ExecutionStrategy$Factory”上抛出 NoClassDefFoundError