Skip to content

Commit 224e49b

Browse files
committed
Added logger, args support, and some bug fixes
1 parent 81e0f15 commit 224e49b

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.idea
2-
*/__pycache__
2+
__pycache__
33
test.py

discord_slash/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@
2323
"""
2424

2525
from .client import SlashCommand
26+
from .model import SlashContext
27+
from .utils import manage_commands
2628

2729
__version__ = "0.1.0"

discord_slash/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import typing
23
import discord
34
from discord.ext import commands
@@ -15,17 +16,21 @@ def __init__(self,
1516
self._discord = client
1617
self.commands = {}
1718
self.http = http.SlashCommandRequest()
19+
self.logger = logging.getLogger("discord_slash")
1820
self._discord.add_listener(self.on_socket_response)
1921

2022
def slash(self, name=None):
2123
def wrapper(cmd):
2224
self.commands[cmd.__name__ if not name else name] = cmd
25+
self.logger.debug(f"Added command `{cmd.__name__ if not name else name}`")
26+
return cmd
2327
return wrapper
2428

2529
async def on_socket_response(self, msg):
2630
if not msg["t"] == "INTERACTION_CREATE":
2731
return
2832
to_use = msg["d"]
2933
if to_use["data"]["name"] in self.commands.keys():
34+
args = [x["value"] for x in to_use["data"]["options"]] if "options" in to_use["data"] else []
3035
ctx = model.SlashContext(self.http, to_use, self._discord)
31-
await self.commands[to_use["data"]["name"]](ctx)
36+
await self.commands[to_use["data"]["name"]](ctx, *args)

discord_slash/error.py

Whitespace-only changes.

discord_slash/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ async def send(self,
2222
text: str = "",
2323
embeds: typing.List[discord.Embed] = None,
2424
tts: bool = False):
25+
if embeds and len(embeds) > 10:
26+
raise
2527
base = {
2628
"type": send_type,
2729
"data": {

discord_slash/utils/manage_commands.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ async def add_slash_command(bot_id,
88
description: str,
99
options: list = None):
1010
url = f"https://discord.com/api/v8/applications/{bot_id}"
11-
url += "/commands" if guild_id else f"/guilds/{guild_id}/commands"
11+
url += "/commands" if not guild_id else f"/guilds/{guild_id}/commands"
1212
base = {
1313
"name": cmd_name,
1414
"description": description,
1515
"options": options if options else []
1616
}
17+
print(url)
18+
print(base)
1719

1820
async with aiohttp.ClientSession() as session:
1921
async with session.post(url, headers={"Authorization": f"Bot {bot_token}"}, json=base) as resp:
@@ -25,7 +27,7 @@ async def remove_slash_command(bot_id,
2527
guild_id,
2628
cmd_id):
2729
url = f"https://discord.com/api/v8/applications/{bot_id}"
28-
url += "/commands" if guild_id else f"/guilds/{guild_id}/commands"
30+
url += "/commands" if not guild_id else f"/guilds/{guild_id}/commands"
2931
url += f"/{cmd_id}"
3032
async with aiohttp.ClientSession() as session:
3133
async with session.delete(url, headers={"Authorization": f"Bot {bot_token}"}) as resp:
@@ -46,8 +48,8 @@ def create_option(name: str,
4648
}
4749

4850

49-
def create_choices(value: str, description: str):
51+
def create_choices(value: str, name: str):
5052
return {
5153
"value": value,
52-
"name": description
54+
"name": name
5355
}

0 commit comments

Comments
 (0)