0
votes

I am trying to make something that will send a notification to my phone via discord when a webhook is called. The notification should have a body of text, and could be something like a python error, or just some plain simple text like "hi there".

I built a discord bot that uses an overridden python BaseHTTPRequestHandler, running in its own thread, which sends the server messages via client.loop.create_task(self.get_channel_by_name(name).send(message)). However, it is pretty slow (takes a few seconds to half a minute to go from webhook to server message, when it really should be almost instantaneous)

I'm thinking I have taken the wrong roundabout method for building my webhook discord server, but I have no idea the right way to go about this, and though I would ask the community. Any thoughts on how to go from requesting a specific file like "http://localhost:8000/post/category/channel/encoded-message", to the specified message in my discord server in a specific channel in a given category? Thanks for any advice!

1

1 Answers

0
votes

I figured it out after a bit of googling. Here[https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types] is the discord api for creating bots using webhooks. The trick is you go to the channel of the server you want to send messages to, and in the settings, add a webhook in the intergration tab. No need to mess around with the discord python package. I managed to start sending messages using python requests library, and nothing else.

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