-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (27 loc) · 908 Bytes
/
Copy pathmain.py
File metadata and controls
33 lines (27 loc) · 908 Bytes
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
# main.py
import asyncio
import discord
import os
from discord.ext import commands
from dotenv import load_dotenv
# Takes bot token and command prefix from .env file
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
PREFIX = os.getenv('COMMAND_PREFIX')
# Establishes intents (events that the bot watches for and responds to) and connect bot to discord
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix = PREFIX, intents=intents)
# Lets us know that the bot is online
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
# Loads all command groups (cogs) into main.py
async def load():
for filename in os.listdir('./commands'):
if filename.endswith('.py'):
await bot.load_extension(f'commands.{filename[:-3]}')
async def main():
await load()
await bot.start(TOKEN)
asyncio.run(main())