Search code examples
discorddiscord.jsdiscord.pybotsnextcord

Trigger Discord Bot event from external API


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. enter image description hereenter image description here

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)


Solution

  • Got a better way to achieve this using help from Discord Developers Community

    EXPECTED BEHAVIOUR:

    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)

    HINT RECEIVED FROM COMMUNITY:

    Help I received from community moderator AEnterprise is in the below image with reference to this documentation section Answer

    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) postman request

    Add Header Authorization with value Bot <Paste your Bot Token Here>

    RESULT ACHIEVED: Message received on Discord Channel in which bot is added already. bot message