【问题标题】:Is there a way to see if a member is being mentioned in the embed?有没有办法查看嵌入中是否提到了成员?
【发布时间】:2021-10-25 04:15:09
【问题描述】:

我正在使用 discord.py,我试图从命令中获取成员对象,当按下按钮时,它会编辑消息并显示用户 mod 日志数据。我让它工作了,但是以一种奇怪的方式,它在消息中对人进行 ping,然后事件检查是否有 ping(交互)我想知道是否有办法查看嵌入内容提及而不是 interaction.message.mentions 是否有类似的东西用于嵌入而不是message?提前致谢!


@client.command()
async def modlogs(ctx, member: discord.Member): 
        main=discord.Embed(title=" ", description=f"{ctx.author.mention} please use the buttons below to navigate {member.mention}'s modlogs.", color=0x76dba8)
        main.set_author(name=f"{member}", icon_url = member.avatar_url)
        ram_member = member

        await ctx.send(f"{member.mention}",
        embed = main,
        components=[[
            Button(style=ButtonStyle.blue, label="Warnings", custom_id= "blue"),Button(style=ButtonStyle.blue, label="Kicks", custom_id= "red"),Button(style=ButtonStyle.blue, label="Bans", custom_id= "green")
        ]],
    )


@client.event
async def on_button_click(interaction):
    print(interaction.message)
    if interaction.message.mentions:
        if (interaction.message.mentions.__len__() > 0):
            for member in interaction.message.mentions:
                if collection2.count_documents({"_id": member.id}) == 0:
                    embed1=discord.Embed(description=f"{member.mention} has no warnings!", color=0xff0000)
                    embed1.set_author(name="Error")
                else:    

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    获取消息

    Msg = await Bot.get_message(channel, id)
    

    获取嵌入

    查看 [this question][1] 的第一个答案。
    Emb = discord.Embed.from_data(Msg.embeds[0])
    

    获取字段

    看看[这个问题][2]的答案。
    for field in Emb.fields:
        print(field.name)
        print(field.value)
    

    获取描述

    查看 [this question][3] 的第一个答案。
    Des = Emb.description
    

    搜索提及

    >>> Member.mention in Des
    True
    

    搜索提及

    提及以 ```@!``` 开头并以 ```>``` 结尾。
    因此,您可以使用此事实将提及项搜索到字符串中(Embed.description 返回字符串类型对象)。
    像这样:
    Men = Des[Des.find("<@!"):Des.find(">")]
    UserID = int(Men[3:])
    Member = ctx.fetch_user(UserID)
    

    链接

    1. Discord.py get message embed
    2. How to align fields in discord.py embedded messages
    3. discord.py Check content of embed title
    4. How do I mention a user using user's id in discord.py?

    总结

    我想它会起作用的。

    【讨论】:

    • 好吧,这真的行不通,因为我正在尝试获取“会员”,所以我无法真正搜索“会员”的描述
    • @ECO3X10C,您是否需要从嵌入描述中的提及中获取成员对象,对吗?让我编辑我的答案
    • 是的,我需要从嵌入描述中获取。
    猜你喜欢
    • 1970-01-01
    • 2011-02-15
    • 2012-06-30
    • 1970-01-01
    • 2021-10-20
    • 2020-11-25
    • 2014-12-22
    • 2011-03-06
    • 1970-01-01
    相关资源
    最近更新 更多