A simple API wrapper for Discord interactions.
Project description
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.
Context Menus
This basic example shows how to add a message context menu.
from discord_slash.context import MenuContext
from discord_slash.model import ContextMenuType
@slash.context_menu(target=ContextMenuType.MESSAGE,
name="commandname",
guild_ids=[789032594456576001])
async def commandname(ctx: MenuContext):
await ctx.send(
content=f"Responded! The content of the message targeted: {ctx.target_message.content}",
hidden=True
)
Advanced
For more advanced use, please refer to our official documentation on context menus here.
- The discord-interactions library is based off of API gateway events. If you are looking for a library webserver-based, please consider:
- If you are looking for a similar library for other languages, please refer to here:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file discord-py-interactions-3.0.2.tar.gz
.
File metadata
- Download URL: discord-py-interactions-3.0.2.tar.gz
- Upload date:
- Size: 41.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14f11c2333a2287991abfe5169cd7be5d25fdaadec546f0da6cbd3de00fc75bd |
|
MD5 | d6b2ef0c41eded91cdc0a815ec83a77d |
|
BLAKE2b-256 | b8f09c52c9c882e40480f0a0b05e0a5df1911df413435d9d8c2401a8c8c732a7 |
File details
Details for the file discord_py_interactions-3.0.2-py3-none-any.whl
.
File metadata
- Download URL: discord_py_interactions-3.0.2-py3-none-any.whl
- Upload date:
- Size: 45.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b50eb92d2b86bda71b02077d95a3089205f6b981baea28304ee80916e0a22029 |
|
MD5 | 99fe8a0c2dd6eb6aff257af5bbba1e0a |
|
BLAKE2b-256 | 98dd8a8c12902d9edcfb8d63325afbc258ea316bbbd57cc12a6a07f40cb96b23 |