Skip to main content

A simple interaction handler for discord.py.

Project description

discord-py-interactions

Your ultimate Discord interactions library for discord.py.

About | Installation | Examples | Discord | PyPI

About

What is discord-interactions?

discord-interactions is, in the simplest terms, a library extension that builds off of the currently existing discord.py API wrapper. While we do use our own basic class code for our own library, a large majority of this library uses discord.py base events in order to make contextualization of interactions relatively easy for us.

When did this begin?

In mid-December of 2020, Discord released the very first type of components, slash commands. These were relatively primitive at the time of their debut, however, over time they slowly came to grew more complex and mutable. This library was created 2 days after the release of slash commands to Discord, and ever since has been actively growing.

What do we currently support?

At this time, we are able to provide you an non-exhaustive list (because Discord are actively creating more interactions at this time) of all components integrated as interactions:

  • Slash Commands
  • Buttons
  • Selects (also known as dropdowns or menus)

Installation

We recommend using pip in order to install our library. You are able to do this by typing the following line below:

pip install -U discord-py-slash-command

Examples

Slash Commands

This example shows a very quick and simplistic solution to implementing a slash command.

from discord import Client, Intents, Embed
from discord_slash import SlashCommand, SlashContext

bot = Client(intents=Intents.default())
slash = SlashCommand(bot)

@slash.slash(name="test")
async def test(ctx: SlashContext):
    embed = Embed(title="Embed Test")
    await ctx.send(embed=embed)

bot.run("discord_token")

Cogs

This example serves as an alternative method for using slash commands in a cog instead.

# bot.py
from discord import Client, Intents, Embed
from discord_slash import SlashCommand, SlashContext

bot = Client(intents=Intents.default())
slash = SlashCommand(bot)

bot.load_extension("cog")
bot.run("discord_token")

# cog.py
from discord import Embed
from discord_slash import cog_ext, SlashContext

class Slash(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @cog_ext.cog_slash(name="test")
    async def _test(self, ctx: SlashContext):
        embed = Embed(title="Embed Test")
        await ctx.send(embed=embed)

def setup(bot):
    bot.add_cog(Slash(bot))

Buttons

This basic example shows how to easily integrate buttons into your commands. Buttons are not limited to slash commands and may be used in regular discord.py commands as well.

from discord_slash.utils.manage_components import create_button, create_actionrow
from discord_slash.model import ButtonStyle

buttons = [
    create_button(style=ButtonStyle.green, label="A green button"),
    create_button(style=ButtonStyle.blue, label="A blue button")
]
action_row = create_actionrow(*buttons)

await ctx.send(components=[action_row])

Advanced

For more advanced use, please refer to our official documentation on buttons here.

Selects

This basic example shows how to add selects into our bot. Selects offer the same accessibility as buttons do in premise of limitations.

from discord_slash.utils.manage_components import create_select, create_select_option, create_actionrow

select = create_select(
    options=[
        create_select_option("Lab Coat", value="coat", emoji="🥼"),
        create_select_option("Test Tube", value="tube", emoji="🧪"),
        create_select_option("Petri Dish", value="dish", emoji="🧫")
    ],
    placeholder="Choose your option",
    min_values=1, # the minimum number of options a user must select
    max_values=2 # the maximum number of options a user can select
)
action_row = create_actionrow(select)

await ctx.send(components=[action_row])

Advanced

For more advanced use, please refer to our official documentation on selects here.


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

discord-py-slash-command-2.4.2.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

discord_py_slash_command-2.4.2-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file discord-py-slash-command-2.4.2.tar.gz.

File metadata

  • Download URL: discord-py-slash-command-2.4.2.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for discord-py-slash-command-2.4.2.tar.gz
Algorithm Hash digest
SHA256 12491cb2e79778da5539f88b21834dad024f4ff5576341737f0d1c5e6a24ee2c
MD5 e90b64143ad9fda09d3b002a0371dc7f
BLAKE2b-256 b3bcf6e2ca863f130aacc75d735b6492c33da6e583616c6001d54aef1be86bcb

See more details on using hashes here.

File details

Details for the file discord_py_slash_command-2.4.2-py3-none-any.whl.

File metadata

  • Download URL: discord_py_slash_command-2.4.2-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for discord_py_slash_command-2.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 00aabfc11b905785c55a199f896812b6986a1d1d378ca248264e4fdbfc58ca05
MD5 e266efc12931432921338c729aa36c0f
BLAKE2b-256 7c3a8f511fbd80164e9295d741bb8bd5e8e53b5506f286490d8f4ef73cf204a6

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