File tree Expand file tree Collapse file tree 6 files changed +17
-6
lines changed Expand file tree Collapse file tree 6 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 11.idea
2- * / __pycache__
2+ __pycache__
33test.py
Original file line number Diff line number Diff line change 2323"""
2424
2525from .client import SlashCommand
26+ from .model import SlashContext
27+ from .utils import manage_commands
2628
2729__version__ = "0.1.0"
Original file line number Diff line number Diff line change 1+ import logging
12import typing
23import discord
34from 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 )
Original file line number Diff line number Diff 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" : {
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments