-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
42 lines (32 loc) · 1.53 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
# Main starting file for BUSTER.
# This file creates the Bot object, loads the cogs, and starts the event loop
from discord.ext import commands
from dotenv import load_dotenv
from os import getenv
import discord
# env must be loaded before importing ./cogs.py
load_dotenv()
TOKEN = getenv('DISCORD_TOKEN') # API token for the bot
GUILD = getenv('DISCORD_GUILD') # ID of desired guild for bot to interact with
if TOKEN is None or GUILD is None:
exit('Environment file missing/corrupted. Halting now!')
# Local dependencies
from cogs import add_cogs
from help_command import CustomHelpCommand
bot = commands.Bot(command_prefix='$', help_command=CustomHelpCommand(), intents=discord.Intents.all(),
case_insensitive=True, activity=discord.Activity(type=discord.ActivityType.watching,
name="over the server - awaiting $help"))
# Runs when bot has successfully logged in
# Note: This can and will be called multiple times during the bot's up-time
@bot.event
async def on_ready():
guild = discord.utils.get(bot.guilds, name=GUILD)
# Only add cogs if no cogs are currently present on the bot
# This prevents the recurring CommandRegistrationError exception
if not bot.cogs:
await add_cogs(bot, guild)
print(f'{bot.user} is connected to the following guild:\n'
f'{guild.name} (ID: {guild.id})\n'
f'Guild Members: {len(guild.members)}\n')
# Begin the bot's event loop
bot.run(TOKEN)