Search code examples
djangodiscord.pydjango-signals

How To Run Discord bot inside Django and use signals with it


So I have created my django website and. I want to run my discord bot inside my django website And also **can I use the signals to send a message on my server if post have been crated ** So any one can help me how to do that


Solution

  • It is really hard to run both a discord bot and a Django website in a single script. I wouldn't recommend it.

    The easiest approach would be using the discord API and making requests to it.

    However, if you still want to use specifically discord.py you can use webhooks:
    Firstly create a webhook:

    Go to Server Settings > Integrations > Webhooks > Create Webhook

    And copy the webhook URL

    import requests  # pip install requests
    from discord import SyncWebhook
    
    webhook_url = "your webhook URL"
    session = requests.Session()
    
    webhook = SyncWebhook.from_url(webhook_url, session=session)
    
    # To send a message
    webhook.send("New post has been created")