Skip to main content

Interface server connecting Django's channels and Discord

Project description

Channels-Discord

Django Channels Discord is a bridge between Discord (specifically, the discord.py Python library) 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 git+https://github.com/AdvocatesInc/django-channels-discord.git@0.1

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

channels_discord-0.3.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file channels_discord-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: channels_discord-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

File hashes

Hashes for channels_discord-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 becc66b853bf7f5c6bd7a433ab3f8b2dcfd169758492fcd24ed6b2c52016ae06
MD5 cbd7d7b34266f36e62505c07ab9f30f3
BLAKE2b-256 71285d7e1c85e573d0f65e19649002a764953f9da5517ddbc570b92e67ad6e57

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page