-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbonebot.py
More file actions
71 lines (55 loc) · 1.94 KB
/
bonebot.py
File metadata and controls
71 lines (55 loc) · 1.94 KB
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
64
65
66
67
68
69
70
71
import os
import discord
import typing
from discord.ext import commands
import logging
import json
import menu_cog
import quotes_cog
logging.basicConfig(level=logging.INFO)
# loads config file
if os.path.exists(os.getcwd() + "/config.json"):
with open(os.getcwd() + "/config.json") as f:
config_data = json.load(f)
else:
config_template = {"prefix": "!", "token": "", "menuChannels": [], "randomFooterMessages": True,
"footerMessages": [], "quotesChannel": 0} # default template for config file
with open(os.getcwd() + "/config.json", "w+") as f:
json.dump(config_template, f)
token = config_data["token"]
description = """Sends updates and prints RHIT menu"""
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=config_data["prefix"], description=description, intents=intents)
tree = bot.tree
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
print("------")
await bot.add_cog(menu_cog.MenuCog(bot, config_data))
await bot.add_cog(quotes_cog.QuotesCog(bot, config_data))
# await tree.sync(guild=discord.Object(id=917618398819659866))
# !sync ~ for guild sync
@bot.command()
@commands.is_owner()
async def sync(ctx: commands.Context, guilds: commands.Greedy[discord.Object], spec: typing.Optional[typing.Literal["~"]] = None) -> None:
if not guilds:
if spec == "~":
fmt = await ctx.bot.tree.sync(guild=ctx.guild)
else:
fmt = await ctx.bot.tree.sync()
await ctx.send(
f"Synced {len(fmt)} commands {'globally' if spec is not None else 'to the current guild.'}"
)
return
assert guilds is not None
fmt = 0
for guild in guilds:
try:
await ctx.bot.tree.sync(guild=guild)
except discord.HTTPException:
pass
else:
fmt += 1
await ctx.send(f"Synced the tree to {fmt}/{len(guilds)} guilds.")
bot.run(token)