forked from sidhant-sriv/ultrachat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
68 lines (48 loc) · 1.67 KB
/
app.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
64
65
66
67
68
from typing import Final
from dotenv import load_dotenv
from discord import Intents
from discord.ext import commands
import os
import asyncio
# STEP 0: LOAD OUR TOKEN FROM SOMEWHERE SAFE
load_dotenv()
TOKEN: Final[str] = os.getenv('DISCORD_TOKEN')
# STEP 1: BOT SETUP
intents: Intents = Intents.all()
intents.message_content = True # NOQA
bot = commands.Bot(command_prefix='!', intents=intents)
EXCLUDED_FILES = ['music.py', 'summarise.py'] #files that might be in the cogs folder but need not to be loaded
EXCLUDED_COMMANDS = ['help']
#Removing default commands
for i in EXCLUDED_COMMANDS:
bot.remove_command(i)
# STEP 2: HANDLING THE STARTUP FOR OUR BOT
@bot.event
async def on_ready() -> None:
print(f'{bot.user} is now running!')
#Syncing slash commands
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} commands")
except Exception as e:
print("exception in command syncing:", e)
@bot.command(name="commands", description="Returns all commands available")
async def commands(ctx):
helptext = "```"
for command in bot.commands:
helptext+=f"{command}\n"
helptext+="```"
await ctx.send(helptext)
#STEP 3: Cog Loading
async def load() -> None:
"""loads cogs present in .\\cogs"""
for filename in os.listdir("./cogs"):
if filename.endswith(".py") and filename not in EXCLUDED_FILES:
await bot.load_extension(f'cogs.{filename[:-3]}')
# STEP 4: MAIN ENTRY POINT
async def main() -> None:
async with bot:
await load()
await bot.start(TOKEN)
if __name__ == '__main__':
asyncio.run(main())