【问题标题】:discord.py not reaction on embed messagediscord.py 对嵌入消息没有反应
【发布时间】:2021-07-25 07:51:30
【问题描述】:

所以我正在尝试编写一个命令,当它看到带有“Diona”的消息时会做出反应

async def on_message(message):
channel = message.channel
emoji = '\N{THUMBS UP SIGN}'
if "Diona" in message.content: 
    await message.add_reaction(emoji)

当用户发送“Diona”时,它对用户有效,但当它来自带有嵌入消息的机器人时,它不会对其做出反应。如何让它发挥作用?

【问题讨论】:

  • 你必须检测嵌入的内容。它们的工作方式与普通消息不同。

标签: python discord discord.py bots


【解决方案1】:

您可以通过循环message.embeds 并遍历所有字段来获取嵌入内容,获取标题和描述:

@client.event
async def on_message(message):
    all_data = ""
    if len(message.embeds) > 0:
        for embed in message.embeds: #loop through all embeds in the message
            try: #I use try and except for every, because when the field is empty, TypeError is raised.
                all_data = all_data + embed.description #get embed description
            except TypeError:
                pass
            try:
                all_data = all_data + embed.title #get embed title
            except TypeError:
                pass
            for field in embed.fields: #loop through each field
                try:
                    all_data = all_data + field.value #get value of field
                except TypeError:
                    pass
                try:
                    all_data = all_data + field.name #get name of field
                except TypeError:
                    pass
    if "Diona" in all_data: #test if Diona is in any of the data we got
        await message.add_reaction(emoji)
    if "Diona" in message.content: 
        await message.add_reaction(emoji)

参考资料:

【讨论】:

    猜你喜欢
    • 2020-11-07
    • 2022-01-25
    • 2020-03-03
    • 2021-06-15
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    相关资源
    最近更新 更多