-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
44 lines (37 loc) · 1.4 KB
/
bot.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
import discord
import asyncio
import config
import os
from discord.ext import commands
from cogwatch import Watcher
# Set up the bot with a command prefix
bot = commands.Bot(command_prefix = '.', intents = discord.Intents.all())
bot.remove_command('help')
# When the bot joins a server, create a channel category for groups to be placed
@bot.event
async def on_guild_join(guild):
category_name = config.CATEGORY_NAME
category = discord.utils.get(guild.categories, name = category_name)
if category is None:
category = await guild.create_category(category_name)
print(f'Category "{category_name}" created in guild "{guild.name}".')
else:
print(f'Category "{category_name}" already exists in guild "{guild.name}".')
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name} ({bot.user.id})')
print('------')
# This is just so if you change a command in the cogs folder it will automatically reload it
watcher = Watcher(bot, path = 'cogs', preload = True, debug = False)
await watcher.start()
async def load():
# Load py files in cogs folder
for filename in os.listdir("./cogs"):
if filename.endswith('.py'):
await bot.load_extension(f'cogs.{filename[:-3]}')
async def main():
await load()
# Run the bot
await bot.start(config.TOKEN)
# asyncio.run just allows you to run async functions in python
asyncio.run(main())