此问题曾被问过(How to get the message content printed out of a discord webook! in python),但已被关闭。因此,我希望我有权利就该主题提出一个新问题?
以下szenario:
我们使用gitlab(https://docs.gitlab.com/ee/user/project/integrations/discord_notifications.html)的discord通知服务,使用discord.py将新的发行/推送到主通知发布到我们的不和谐频道之一。该通道还通过漫游器链接到另一个聊天,因此两个聊天始终具有相同的内容。到目前为止,这是可行的。
当我现在尝试获取print(message.content)
时,关于gitlab消息的消息为空,即使它显示的消息不一致。基本结构如下:
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的信息的更多详细信息,但是它没有记录任何事件(设置为“新问题”,创建了多个事件),而监听器对于不和谐(在新消息上),效果很好。
设置如下:
在这种情况下,我不知道如何获取GitLab发送给Discord的头数据。我还使用Postman检查了Discord提供的Webhook-它仅返回Bots的基本统计信息。
答案 0 :(得分:0)
GitLab以嵌入(https://discordpy.readthedocs.io/en/latest/api.html#embed)的形式发送消息内容
就我而言,我正在寻找的信息就在我眼前。您可以使用message.embeds[0].description
来访问它。
我无法对要嵌入的API描述进行正面或反面,但是看来,我也从未测试过它的作用,然后开始盘旋。