This question has been asked before (How to get the message content printed out of a discord webook! in python) but has been closed. So I hope I'm within my rights to open a new question on the topic?
The following szenario:
We use the discord notification service from gitlab (https://docs.gitlab.com/ee/user/project/integrations/discord_notifications.html) to post new issue/push to master-notifications to one of our discord channels using discord.py. This channel is also linked to another chat via bot so that both chats always have the same content. This is working so far.
When I now try to get print(message.content) it's empty concerning messages from gitlab, even though it displays a message in discord. The basic structure looks like this:
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) returns something like <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>>
I did read large parts of the API reference (https://discordpy.readthedocs.io/en/latest/api.html) but could not find anything. Though I could not make heads or tails of the webhook part (https://discordpy.readthedocs.io/en/latest/api.html#webhook-support).
Any ideas how to obtain the message content from a message that comes from a webhook? It's gotta be somewhere ...
Thank you in advance, Christian
Update 2020-10-23
I have tried getting more details about the information send from GitLab to Discord by creating an event listener via https://pipedream.com/ but it did not record any events (set to "new issue", created several), while a listener for discord (on new messages) worked fine.
The setup is as follows:
- Create a Webhook in Discord (https://discord.com/api/webhooks/[id]/[token])
- Feed said Webhook into the settings in GitLab and choose from a multitude of triggers.
I do not know how I could get the header-data GitLab sends to Discord under these circumstances. I also checked the Webhook provided by Discord using Postman - it merely returns the Bots basic stats.