Skip to main content

A Python wrapper for the Discord API

Project description

A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python.


Discord server invite PyPI version info PyPI supported Python versions Documentation Status

PLEASE NOTE: This is a fork of OG discord.py by Rapptz! Since Danny no longer maintains dpy so I created this lib in order to add any upcoming feature from Discord and I’m using Maya’s slash command wrapper for application commands.

Key Features

  • Modern Pythonic API using async and await.

  • Proper rate limit handling.

  • Command extension to aid with bot creation

  • Easy to use with an object oriented design

  • 100% coverage of the supported Discord API.

  • Optimised in both speed and memory.

Installing

Python 3.8 or higher is required

To install the library without full voice support, you can just run the following command:

# Linux/macOS
python3 -m pip install -U zarenacord

# Windows
py -3 -m pip install -U zarenacord

Otherwise to get voice support you should run the following command:

# Linux/macOS
python3 -m pip install -U "zarenacord[voice]"

# Windows
py -3 -m pip install -U zarenacord[voice]

To install the development version, do the following:

$ git clone https://github.com/Zarenalabs/zarenacord.git
$ cd zarenacord
$ python3 -m pip install -U .[voice]

Optional Packages

Please note that on Linux installing voice you must install the following packages via your favourite package manager (e.g. apt, dnf, etc) before running the above commands:

  • libffi-dev (or libffi-devel on some systems)

  • python-dev (e.g. python3.6-dev for Python 3.6)

Quick Example

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
        if message.author == self.user:
            return

        if message.content == 'ping':
            await message.channel.send('pong')

client = MyClient()
client.run('token')

Bot Example

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.command()
async def ping(ctx):
    await ctx.send('pong')

bot.run('token')

Application Commands Example

zarena defines a bot subclass to automatically handle posting updated commands to discords api. This isn’t required but highly recommended to use.

class MyBot(zarena.Bot):
    def __init__(self):
        super().__init__(command_prefix="!")  # command prefix only applies to message based commands

        self.load_extension("cogs.my_cog")  # important!

if __name__ == '__main__':
    MyBot().run("token")

Sample cog:

class MyCog(zarena.ApplicationCog):

    # slash command
    @zarena.slash_command()
    async def slash(self, ctx: zarena.Context, number: int):
        await ctx.send(f"You selected #{number}!", ephemeral=True)

    #  message context menus
    @zarena.message_command(name="Quote")
    async def quote(self, ctx: zarena.Context, message: discord.Message):
        await ctx.send(f'> {message.clean_content}\n- {message.author}')

    # user context menus
    @zarena.user_command(name='Cookie')
    async def cookie(self, ctx: zarena.Context, user: discord.Member):
        await ctx.send(f'{ctx.author} gave cookie to {user} 🍪')

Project details


Download files

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

Source Distribution

zarenacord-2.0.0.tar.gz (824.5 kB view hashes)

Uploaded Source

Built Distribution

zarenacord-2.0.0-py3-none-any.whl (913.4 kB view hashes)

Uploaded Python 3

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