I am making a discord bot in Python using Nextcord.
Slash commands are working fine, and I am able to send messages in the Discord channel.
Now what I am trying to achieve is, when there is a new sale in my Django website, I want my discord bot to send a message with its details.
Points to note:
- I can easily make API call with data from Django
- I don’t want to use the Discord channel webhook option
- I don’t want a discord bot to send multiple API calls after a duration to check if a new sale is made or not
- The event should initiate from the Django server when a new sale is made on the website.
- My discord bot is hosted on an AWS ec2 ubuntu server for development. (this I will change later)
I have gone through the Discord developer’s documentation and don’t seem to find anything helpful.
Any help is appreciated.
I am expecting a message from my discord bot in the Discord server on an event triggered from another platform (in this case, an event/API call is initiated from Django server/website and my bot should send a message in Discord server)
2
Answers
Got a better way to achieve this using help from Discord Developers Community
EXPECTED BEHAVIOUR:
HINT RECEIVED FROM COMMUNITY:
Help I received from community moderator AEnterprise is in the below image with reference to this documentation section
API CALL TO SEND MESSAGE:
When I tried this using my Bot token, it worked! API call (tested in postman, will work same on any platform)
Add Header Authorization with value
Bot <Paste your Bot Token Here>
RESULT ACHIEVED: Message received on Discord Channel in which bot is added already.
I would recommend
nextcord-ext-ipc
for simple communication from your web server to your bot. This is easiest to implement securely if you run both the web server and bot on the same machine.There are examples in the documentation to get you started. You would need a route on the bot side to accept an "event" on sale, and to invoke this via the
Client
on the web server side.The example uses Quart but this transfers to any Python web server, as long as you can create a
Client
instance and use therequest
method on it.