-
Notifications
You must be signed in to change notification settings - Fork 1
/
launcher.py
63 lines (52 loc) · 1.92 KB
/
launcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from typing import Literal, Optional
from discord.ext import commands
from discord.ext.commands import Greedy, Context
import discord
import config
class Bot(commands.Bot):
def __init__(self, intents: discord.Intents, **kwargs):
super().__init__(command_prefix=commands.when_mentioned_or('?'), intents=intents, **kwargs)
async def setup_hook(self):
# Loading cogs
for cog in config.cogs:
try:
await self.load_extension(cog)
except Exception as exc:
print(f'Could not load extension {cog} due to {exc.__class__.__name__}: {exc}')
async def on_ready(self):
print(f'Logged on as {self.user} (ID: {self.user.id})')
print('----------')
intents = discord.Intents.default()
intents.message_content = True
bot = Bot(intents=intents)
@bot.command()
@commands.guild_only()
@commands.check(lambda ctx: ctx.author.id in config.admins)
async def sync(
ctx: Context, guilds: Greedy[discord.Object], spec: Optional[Literal["~", "*", "^"]] = None) -> None:
if not guilds:
if spec == "~":
synced = await ctx.bot.tree.sync(guild=ctx.guild)
elif spec == "*":
ctx.bot.tree.copy_global_to(guild=ctx.guild)
synced = await ctx.bot.tree.sync(guild=ctx.guild)
elif spec == "^":
ctx.bot.tree.clear_commands(guild=ctx.guild)
await ctx.bot.tree.sync(guild=ctx.guild)
synced = []
else:
synced = await ctx.bot.tree.sync()
await ctx.send(
f"Synced {len(synced)} commands {'globally' if spec is None else 'to the current guild.'}"
)
return
ret = 0
for guild in guilds:
try:
await ctx.bot.tree.sync(guild=guild)
except discord.HTTPException:
pass
else:
ret += 1
await ctx.send(f"Synced the tree to {ret}/{len(guilds)}.")
bot.run(config.token)