首页 > 解决方案 > 文本检测 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) 如果它没有任何文本则应该发布一个普通的图像帖子。但是文字不起作用。没有一个错误,我需要你们的帮助!

标签: pythondiscord.pypraw

解决方案


推荐阅读