Skip to main content

Channels-Discord

Django Channels Discord is a bridge between Discord (currently using the pycord Python library, but this may be a stopgap while we wait for the dust to settle after discord.py's implosion) and Django's channels). It contains both a new interface server for connecting to Discord and Channels consumers -- everything you need to turn your Django app into an Discord chatbot, chat monitoring/moderating service, or whatever else you might use a real-time Discord client to do.

This project is more of a stub right now, and will be more further fleshed out as new features are wired up from discord.py.

Requirements

Most of the requirements can be found in setup.py, but the most important note is that this requires library requires Django Channels 3+ -- Channels 1.x and 2.x are not supported.

Installation

Install the package from github:

pip install channels-discord

Basic Usage

  1. Add the library to INSTALLED_APPS:

    INSTALLED_APPS = (
        ...
        'channels_discord',
    )
    
  2. Create a Consumer

    Create a new consumer by inheriting from DiscordConsumer:

    from channels_discord import DiscordConsumer
    
    class MyDiscordConsumer(DiscordConsumer):
        def ready(self):
            """
            Optional hook for actions on connection to Discord
            """
            print('You are now connected to discord!')
    
        def my_custom_message(self):
            """
            Use built-in functions to send basic discord actions
            """
            self.send_action('dm', user_id='SOME_DISCORD_USER_ID', text='your message')
            self.send_action(
                'send_to_channel',
                channel_id='SOME_DISCORD_CHANNEL_ID',
                text='your message'
            )
    
  3. Add your consumer(s) to your router

    You can use the discord type in channels ProtocolTypeRouter to connect your new consumer to the interface server, and ensure your discord messages are delivered to the right place:

    from channels.routing import ProtocolTypeRouter
    from myapp.consumers import MyDiscordConsumer
    
    application = ProtocolTypeRouter({
        'discord': MyDiscordConsumer,
    })
    
  4. Start the interface server

    The interface server can be started by simply running this in the command line:

    channels-discord
    

    The server requires that the token and application properties be set:

    • token: Either a bot auth token or a user access token from user OAuth access. For information on how to acquire these tokens, please see Discord's developer documentation.

    • application: An import string pointing to the location of your app's ASGI application. Hence, if your app was named myapp, contained an ASGI filed called asgi.py, and your ASGI application is named my_application, you could start the server by running:

    channels-discord -t 'MY_LONG_BOT_TOKEN' -a 'myapp.asgi:my_application'
    

    You can also set these values using the env variables CHANNELS_DISCORD_APPLICATION and DISCORD_BOT_TOKEN.

Release files for channels-discord 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for channels-discord 0.4.0
File Size Uploaded
channels_discord-0.4.0.tar.gz 6.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for channels-discord 0.4.0
File Interpreter ABI Platform
channels_discord-0.4.0-py3.8.egg Legacy Egg format - - Details
channels_discord-0.4.0-py3.6.egg Legacy Egg format - - Details
channels_discord-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.2 kB

Release files / channels_discord-0.4.0.tar.gz

Download URL channels_discord-0.4.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cbba76780b743fc5cc767510ef0f20591974698412b2da7c2f708ec3a7810280
BLAKE2b-256 checksum
How to use checksums
0c7fcdd425332afa9f85628f22d62f9ccde97700f8aca0f9b34c727615cd68af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.60.0 importlib-metadata/4.0.1 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.0

Release files / channels_discord-0.4.0-py3.8.egg

Download URL channels_discord-0.4.0-py3.8.egg
Size 10.9 kB
Tags Egg
SHA-256 checksum
How to use checksums
9ddf3a337db51e04e5e0fcf54c5eb2d0f3569b4643c3252536b8bc863ce578d2
BLAKE2b-256 checksum
How to use checksums
2005def4a7f7d6ce2ecefb7ceb634b4726bc06f4d07d2ab48e89bfc9a0367cda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.60.0 importlib-metadata/4.0.1 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.0

Release files / channels_discord-0.4.0-py3.6.egg

Download URL channels_discord-0.4.0-py3.6.egg
Size 10.8 kB
Tags Egg
SHA-256 checksum
How to use checksums
314dfe3dce93e6faec934867ca46865049ec50536923d17405ac5b6a2a06ba72
BLAKE2b-256 checksum
How to use checksums
e9a994d870db50bb5064af470f02de3bec875b7cdb2146c7158ffb178fd619d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.60.0 importlib-metadata/4.0.1 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.0

Release files / channels_discord-0.4.0-py3-none-any.whl

Download URL channels_discord-0.4.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81f6722a23016bd06ace8d5e47d7a311453997c2b57198426342a366effa5098
BLAKE2b-256 checksum
How to use checksums
d6eecc5ac48bc117a994db58b6e784bf51f8e42df01e1a790d3aa6a152c6ab88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.60.0 importlib-metadata/4.0.1 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.0

Release history Release notifications | RSS feed

This release

0.4.0 This release

4 release files

0.3.1

2 release files

0.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page