如何在Python中侦听hookbin webhook?

2024-10-02 04:20:49 发布

您现在位置:Python中文网/ 问答频道 /正文

hookbin-Webhooks允许用户指定在事件发生时接收json格式数据的应用程序的URL。例如,在hookbin中更新事件时。我想创建一个python脚本来接收这些数据并将其打印出来。创建此python脚本的最佳方法是什么


Tags: 数据方法用户脚本json应用程序url格式
1条回答
网友
1楼 · 发布于 2024-10-02 04:20:49

您需要清理hookbin网站。我试过了,到目前为止,这是一个痛苦的过程,当然有可能,但你必须像在浏览器中一样发出请求。如果您需要一个webhook来监听发送的内容,我只需要使用discord webhook,让一个bot在私有服务器中读取它们

机器人脚本

import discord

TOKEN = 'Make your bot at https://discord.com/developers/applications'

client = discord.Client()


@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.author.bot:
        data = message.content
        await message.channel.send(f"Received {data}")
        print(data)
        # anything else you wanted to do with the data
        


client.run(TOKEN)

Webhook脚本

import requests

hook = 'Your Discord Webhook'

data = {
  "content": "This is the data that gets printed to terminal through the bot"
}

r = requests.post(hook, json=data)

唯一的缺点是你不能得到非常具体的细节,但如果你只需要得到内容,它就可以很好地工作。使Bot和webhook成为现实。通过访问dev门户并将其邀请到私有服务器来创建bot,然后通过在任何文本频道的“集成”下创建webhook

Picture1

Picture2

相关问题 更多 >

    热门问题