【问题标题】:discord.py Check content of embed titlediscord.py 检查嵌入标题的内容
【发布时间】:2021-04-09 09:21:56
【问题描述】:

我想做的事:我正在用我的 discord.py 机器人制作一个谜语命令。每次有人为新谜语运行命令时,它都会删除最近固定的消息(所述消息的作者是机器人)并固定新消息。我试图让机器人在嵌入标题中查找某个关键字,而不是依赖于固定消息是否由机器人发送。

问题:我还没有找到检查嵌入标题内容的方法。我发现与我的问题最相关的唯一问题是an on_message() event,但我不太确定如何合并它。

代码

@client.command(aliases=["riddle"],pass_context=True)
@commands.guild_only()
@has_permissions(manage_messages=True)
async def rid(ctx, prize=None, *, rid=None):
    if prize == None and rid == None:
        await ctx.send('Format: `bl!riddle "cool prize" Sometimes it\'s brown and sticky, what is it?`')
    elif prize is not None and rid == None:
        await ctx.send('Format: `bl!riddle "a nice prize" Fluffy like candy but not a cloud, what am I?`')
    elif prize is not None and rid is not None:
        embed = discord.Embed(title, "Today's Riddle: ", description=rid, color=0x8d78d9) # The embed title the bot would read
        embed.set_footer(text=f"Prize: {prize} | Host: {ctx.message.author}")
        try:
            await ctx.message.delete()
        except:
            pass
        pinner = await ctx.send(embed=embed)
        channel = ctx.channel
        pins = await channel.pins()
        x = 1
        while x is not 0:
            for message in pins:
                if message.author.id == 733237477170741280: # this is what I want to replace              
                    await message.unpin()
                    x = x - 1
                else:
                    continue
                if x == 0:
                    break
        await pinner.pin()

图片

这就是嵌入的样子。

我看过的其他问题

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    discord.Embed 对象具有属性titledescription。使用这些,您可以访问嵌入的内容。

    @client.command(aliases=["riddle"],pass_context=True)
    @commands.guild_only()
    @has_permissions(manage_messages=True)
    async def rid(ctx, prize=None, *, rid=None):
        if prize == None and rid == None:
            await ctx.send('Format: `bl!riddle "cool prize" Sometimes it\'s brown and sticky, what is it?`')
        elif prize is not None and rid == None:
            await ctx.send('Format: `bl!riddle "a nice prize" Fluffy like candy but not a cloud, what am I?`')
        elif prize is not None and rid is not None:
            embed = discord.Embed(title="Today's Riddle: ", description=rid, color=0x8d78d9)
            embed.set_footer(text=f"Prize: {prize} | Host: {ctx.message.author}")
            embed_title = embed.title
            embed_desc = embed.description
            ...
    

    编辑

    为了从消息中获取嵌入对象,您可以使用message.embeds。这将为您返回消息包含的嵌入列表。

    【讨论】:

    • 这将用于查找发送的嵌入的标题和描述,是的。但是,您如何在消息中找到embed.titleembed.description?您是否必须阅读message.content 并从那里开始工作?
    • @Bagle 你会使用message.embeds 属性,docs
    猜你喜欢
    • 2021-02-21
    • 2020-10-06
    • 1970-01-01
    • 2021-02-18
    • 2020-08-27
    • 2021-11-21
    • 2019-01-11
    • 2021-07-13
    • 2021-06-18
    相关资源
    最近更新 更多