繁体   English   中英

使用 discord.py 时,如何从(gitlab 通知)webhook 获取消息内容?

[英]How can I get the message content from a (gitlab notification) webhook when using discord.py?

之前已经问过这个问题( How to get the message content print out of an discord webook! in python )但已关闭。 所以我希望我有权就该主题提出新问题?

以下场景:

我们使用来自 gitlab ( https://docs.gitlab.com/ee/user/project/integrations/discord_notifications.html ) 的不和谐通知服务将新问题/推送到主通知发布到我们使用不和谐的不和谐频道之一。 py。 该频道还通过 bot 链接到另一个聊天,以便两个聊天始终具有相同的内容。 到目前为止,这是有效的。

当我现在尝试从 gitlab 获取print(message.content)消息时,它是空的,即使它显示一条不和谐的消息。 基本结构如下所示:

import discord
import re

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as {0}!'.format(self.user))

    async def on_message(self, message):
        # modifying and preparing messages for sync with second chat
        # I removed this because it shouldn't have anything to do with the problem

        # trying to find the message content
        print(message.author)
        print(message.content)
        print(message)
        print('----------')
        
        # write messages into database
    

client = MyClient()
client.run('TOKEN')

print(message)返回类似<Message id=1234 channel=<TextChannel id=5678 name='some-name' position=1 nsfw=False news=False category_id=9012> type=<MessageType.default: 0> author=<User id=3456 name='Bot Name' discriminator='0000' bot=True> flags=<MessageFlags value=0>>

我确实阅读了 API 参考( https://discordpy.readthedocs.io/en/latest/api.html )的大部分内容,但找不到任何内容。 虽然我无法确定 webhook 部分的正面或反面( https://discordpy.readthedocs.io/en/latest/api.html#webhook-support )。

任何想法如何从来自 webhook 的消息中获取消息内容? 它一定在某个地方......

提前谢谢你,克里斯蒂安

更新 2020-10-23

我尝试通过https://pipedream.com/创建事件侦听器来获取有关从 GitLab 发送到 Discord 的信息的更多详细信息,但它没有记录任何事件(设置为“新问题”,创建了多个),而侦听器对于不和谐(在新消息上)工作正常。

设置如下:

  1. 在 Discord 中创建一个 Webhook ( https://discord.com/api/webhooks/[id]/[token] )
  2. 将上述 Webhook 输入 GitLab 中的设置,并从众多触发器中进行选择。

在这种情况下,我不知道如何获得 GitLab 发送到 Discord 的标头数据。 我还使用 Postman 检查了 Discord 提供的 Webhook - 它仅返回 Bots 的基本统计数据。

GitLab 将消息内容作为嵌入发送 ( https://discordpy.readthedocs.io/en/latest/api.html#embed )

就我而言,我正在寻找的信息就在我眼前。 您可以使用message.embeds[0].description访问它。

我无法对嵌入的 API 描述做出正面或反面,但似乎,我也从未测试过它的功能,然后开始兜圈子。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM