【问题标题】:Discord bot that sends messages recieved from webhook发送从 webhook 收到的消息的 Discord 机器人
【发布时间】:2021-10-29 15:50:03
【问题描述】:

我正在尝试制作一些东西,当调用 webhook 时,它会通过不和谐向我的手机发送通知。通知应该有一段文本,可能是 python 错误,或者只是一些简单的文本,如“hi there”。

我构建了一个不和谐的机器人,它使用一个被覆盖的 python BaseHTTPRequestHandler,在它自己的线程中运行,它通过client.loop.create_task(self.get_channel_by_name(name).send(message)) 发送服务器消息。但是,它很慢(从 webhook 到服务器消息需要几秒钟到半分钟,而实际上它应该几乎是瞬时的)

我认为我在构建我的 webhook discord 服务器时采取了错误的迂回方法,但我不知道正确的方法来解决这个问题,尽管我会询问社区。关于如何从请求特定文件(如“http://localhost:8000/post/category/channel/encoded-message”)到给定类别中特定频道中我的不和谐服务器中的指定消息的任何想法?感谢您的建议!

【问题讨论】:

    标签: python-3.x async-await discord discord.py


    【解决方案1】:

    经过一番谷歌搜索后,我想通了。这里 [https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types] 是使用 webhook 创建机器人的不和谐 api。诀窍是您转到要向其发送消息的服务器的通道,然后在设置中的集成选项卡中添加一个 webhook。无需弄乱不和谐的 python 包。我设法开始使用 python 请求库发送消息,仅此而已。

    import requests
    requests.post(f'https://discord.com/api/webhooks/{webhook.id}/{webhook.token}', data={'content':message})
    

    【讨论】:

      猜你喜欢
      • 2021-08-19
      • 2021-01-08
      • 2023-04-03
      • 2020-11-23
      • 2020-03-20
      • 2021-02-22
      • 2019-09-12
      • 2019-03-05
      • 2022-01-23
      相关资源
      最近更新 更多