10
10
import tzlocal
11
11
from apscheduler .schedulers .asyncio import AsyncIOScheduler
12
12
from discord import Guild , Interaction , VoiceChannel
13
- from discord .app_commands import Command
13
+ from discord .app_commands import Command , CommandOnCooldown , MissingPermissions , BotMissingPermissions
14
14
from discord .embeds import Embed
15
- from discord .errors import NotFound
15
+ from discord .errors import NotFound , HTTPException , InteractionResponded
16
16
from discord .ext .commands import AutoShardedBot
17
17
from discord .ext .commands .errors import CommandNotFound , BadArgument
18
+ from discord import AutoShardedClient
18
19
19
20
from lib .config import Config
20
21
from lib .db import DB
21
- from lib .progress import Progress , Timer
22
+ from lib .errors import BotNotReady
23
+ from lib .progress import Progress , Timer , Loading
22
24
from lib .urban import UrbanDictionary
23
25
24
26
COMMAND_ERROR_REGEX = r"Command raised an exception: (.*?(?=: )): (.*)"
@@ -49,10 +51,10 @@ def __init__(self, shards: list[int], version: str):
49
51
self .shard_progress .start ()
50
52
51
53
async def on_connect (self ):
52
- await self .tree .sync ()
53
54
while not self .shards_ready :
54
- print ('Shards Not Ready' )
55
55
await asyncio .sleep (.5 )
56
+ self .tree .copy_global_to (guild = discord .Object (id = "1064582321728143421" ))
57
+ await self .tree .sync (guild = discord .Object (id = "1064582321728143421" ))
56
58
self .register_guilds ()
57
59
asyncio .ensure_future (self .monitor_shutdown ())
58
60
print (f"Signed into { self .user .display_name } #{ self .user .discriminator } " )
@@ -71,29 +73,34 @@ async def on_interaction(self, ctx: Interaction):
71
73
name_list , options = self .get_name (ctx .data , [])
72
74
name = " " .join (name_list )
73
75
self .db .insert .commands (command_name = name , guild_id = ctx .guild_id , user_id = ctx .user .id , params = json .dumps (options ), ts = datetime .now ().timestamp ())
74
- # self.db.run(f"""INSERT INTO commands VALUES (?,?,?,?,?)""", name, ctx.guild_id,
75
- # ctx.user.id, json.dumps(options), datetime.now().timestamp())
76
+ self .db .run (f"""INSERT INTO commands VALUES (?,?,?,?,?)""" , name , ctx .guild_id ,
77
+ ctx .user .id , json .dumps (options ), datetime .now ().timestamp ())
78
+
79
+
76
80
77
81
@staticmethod
78
82
async def send (ctx : Interaction , * args , ** kwargs ):
79
83
if kwargs .get ('embed' ):
80
84
embed : Embed = kwargs ['embed' ]
81
- if not isinstance ( embed .colour , discord . Colour ) :
85
+ if embed .colour is None :
82
86
color = int ("0x" + '' .join ([random .choice ('0123456789ABCDEF' ) for j in range (6 )]), 16 )
83
87
embed .colour = color
84
88
embed .set_footer (text = "Made by Gccody" )
85
89
embed .timestamp = datetime .now ()
86
90
# embed.set_thumbnail(url=self.logo_path)
87
91
kwargs ['embed' ] = embed
92
+
88
93
if ctx .is_expired ():
89
94
channel = ctx .channel
90
95
if not isinstance (channel , VoiceChannel ):
91
96
return await ctx .channel .send (* args , ** kwargs )
92
97
try :
93
- await ctx .original_response ()
94
- return await ctx .followup .send (* args , ** kwargs )
95
- except NotFound :
96
98
return await ctx .response .send_message (* args , ** kwargs )
99
+ except InteractionResponded :
100
+ try :
101
+ return await ctx .followup .send (* args , ** kwargs )
102
+ except NotFound :
103
+ return await ctx .channel .send (* args , ** kwargs )
97
104
98
105
async def monitor_shutdown (self ):
99
106
while True :
@@ -111,6 +118,7 @@ async def monitor_shutdown(self):
111
118
112
119
def register_guilds (self ):
113
120
progress = Progress ('Registering guilds' , len (self .guilds ))
121
+ progress .start ()
114
122
for guild in self .guilds :
115
123
self .db .insert .guilds (id = guild .id )
116
124
progress .next ()
@@ -120,7 +128,6 @@ def register_guilds(self):
120
128
self .db .delete .guilds (id = guild .id )
121
129
self .db .commit ()
122
130
self .ready = True
123
- print ('End' )
124
131
self .tasks .start ()
125
132
126
133
async def on_guild_join (self , guild : Guild ):
0 commit comments