Coder Social home page Coder Social logo

discord-py-interactions-v3's Introduction

discord-py-interactions

Your ultimate Discord interactions library for discord.py.

About | Installation | Examples | Discord | PyPI

About

What happend with original library?

Original library has become a separate wrapper for discord API and got version 4. Its not more extension for discord.py But there are people who want to continue using v3 with discord.py

What is discord-py-interactions?

discord-py-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, Modals

Installation

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

pip uninstall discord-py-interactions

pip install git+https://github.com/Damego/discord-py-interactions.git

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 Intents
from discord.ext.commands import Bot
from discord_slash import SlashCommand

# Note that command_prefix is a required but essentially unused paramater.
# Setting help_command=False ensures that discord.py does not create a !help command.
# Enabling self_bot ensures that the bot does not try and parse messages that start with "!".
bot = Bot(command_prefix="!", self_bot=True, help_command=False, intents=Intents.default())
slash = SlashCommand(bot)

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

# cog.py
from discord import Embed
from discord.ext.commands import Bot, Cog
from discord_slash import cog_ext, SlashContext

class Slash(Cog):
    def __init__(self, bot: 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):
    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.component import Button, ButtonStyle

buttons = [
    Button(style=ButtonStyle.green, label="A green button"),
    Button(style=ButtonStyle.blue, label="A blue button")
]

await ctx.send(components=[buttons])

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.component import Select, SelectOption

select = Select(
    options=[
        SelectOption(label="Lab Coat", value="coat", emoji="🥼"),
        SelectOption(label="Test Tube", value="tube", emoji="🧪"),
        SelectOption(label="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
)

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.


discord-py-interactions-v3's People

Contributors

4surix avatar anand2312 avatar anothercat avatar artem30801 avatar astreatss avatar benwoo1110 avatar boehs avatar chweesee avatar damego avatar eunwoo1104 avatar fayedel avatar geekid812 avatar hpenney2 avatar i0bs avatar jellywx avatar lexicalunit avatar lilspazjoekp avatar lordofpolls avatar mathiassven avatar mavit avatar michaeljharvey avatar mike1808 avatar nkstonks avatar predaaa avatar stellaurora avatar tehstone avatar toricane avatar tthn0 avatar vioshim avatar zevaryx avatar

Watchers

 avatar

discord-py-interactions-v3's Issues

[REQUEST]

What is the feature you're proposing?
Currently, discord supports restricting the type of channel when using the channel option type, documented here. I would like it if those were added to the v3 fork

Additional Information

  • My feature request is related to an existing Issue.
    • Issue (if referenceable):

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.