Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kvsxxx committed Dec 12, 2021
2 parents b68b77e + 911409f commit bb77664
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
3 changes: 3 additions & 0 deletions discord_ui/receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@
'SubSlashInteraction',
'SlashedSubCommand', # deprecated

'ContextInteraction',

'Interaction',
)


class InteractionType:
PING = Ping = 1
APPLICATION_COMMAND = Command = 2
Expand Down
10 changes: 10 additions & 0 deletions docs/source/_static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,23 @@ html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(
max-width: 100%;
}

/* Buttons */
.btn.btn-neutral {
border: 1px solid #2C2F33;
border-radius: 5px;
color: white
}

/* Note box background */
.rst-content .note .admonition-title, .note .admonition-title {
background-color: rgba(88,101,242,.5);
}

/* Warning box title */
.rst-content .warning .admonition-title, .warning .admonition-title {
background-color: #fee65cad;
}
/* Warning box background */
.rst-content .warning, .warning {
background-color: rgba(254,231,92,.5);
}
Expand All @@ -109,6 +113,11 @@ code.docutils.literal.notranslate, .highlight, div.highlight-default.notranslate
color: white;
}


html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.glossary):not(.simple) .descclassname {
color: white;
}

html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.glossary):not(.simple)>dt:first-child {
font-family: SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,Courier,monospace;
color: white;
Expand All @@ -123,6 +132,7 @@ html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(
background-color: #5865F2;
}

/* Navigationsdings */
.wy-side-nav-search, .wy-nav-top {
/* background-color: #5865F2; */
background: #5865F2;
Expand Down
5 changes: 4 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ Here is a list of possible examples of how to use our package
: Sends a hidden select menu to a user, who can choose between roles which he will get upon selecting

- [`staff messager`](https://github.com/discord-py-ui/discord-ui/tree/main/examples/staff_message.py)
: slashcommand with autocomplete for sending messages to a staff mmember
: slashcommand with autocomplete for sending messages to a staff mmember

- [`cog example`](https://github.com/discord-py-ui/discord-ui/tree/main/examples/cogs.py)
: simple example for using application commands in cogs
3 changes: 1 addition & 2 deletions examples/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

import asyncio
from discord.ext import commands
from discord_ui import SlashInteraction, UI, Button
from discord_ui.components import LinkButton
from discord_ui import SlashInteraction, UI, Button, LinkButton

# The main discord bot client
client = commands.Bot(" ")
Expand Down
66 changes: 66 additions & 0 deletions examples/cogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Example by 404kuso
# https://github.com/discord-py-ui/discord-ui/tree/main/examples/cpgs.py
#
# This is just a simple cog command example for application commands
# Note:
# If you want to test this, replace '785567635802816595' in guild_ids=[] with a guild id of
# your choice, because guild slash commands are way faster than globals

# import discord package
import discord
# import commands extention
from discord.ext import commands
from discord_ui import (
UI, cogs, SlashOption,
# interaction types for type hinting
SlashInteraction, AutocompleteInteraction, ContextInteraction,
# overridden message object for type hinting
Message
)

# initialize bot
bot = commands.Bot(" ")


# create the cog
class ExampleCog(commands.Cog):
# add slashcommand to cog
@cogs.slash_command("my_command", "this is an example cog command", guild_ids=[785567635802816595])
# callback for the command
async def my_command(self, ctx: SlashInteraction):
...


# method that generates choices for the 'hello world' command
async def my_generator(self, ctx: AutocompleteInteraction):
return [("hello", "1"), ("world", "2")]

# add subslash command to the cog
@cogs.subslash_command("hello", "world", "example subcommand", [
# simple option that uses autocompletion
SlashOption(str, "argument", "option that autogenerates somethning", choice_generator=my_generator)
])
# callback for the commmand
async def my_subcommand(self, ctx: SlashInteraction, argument: str):
...


# add message command to cog
@cogs.message_command("message", guild_ids=[785567635802816595])
# callbackfor the command
async def my_message_command(self, ctx: ContextInteraction, message: Message):
...


# add user command to cog
@cogs.user_command("user", guild_ids=[785567635802816595])
# callback for the command
async def my_user_command(self, ctx: ContextInteraction, member: discord.Member):
...


# add the cog to the bot
bot.add_cog(ExampleCog())

# login
bot.run("your token")

0 comments on commit bb77664

Please sign in to comment.