-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (40 loc) · 1.57 KB
/
main.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
import importlib
import os
import discord
# imports setup command separately
import src.setup as setup
# for importing commands folder as python modules
import src.commands
# iterates through all files in ./src/commands
for file in os.listdir('./src/commands'):
# if any file is a python file and it's not the init file,
# import it as an absolute module to src.commands, and remove the ending .py
if file.endswith('.py') and file != '__init__.py':
importlib.import_module(f'src.commands.{file[:-3]}')
# get the bot token and the admin usernames
token = setup.get_token()
admin = setup.get_admin()
# add default intents, ensure the messaging intent is added to true,
# and generate a new client
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
# calls an event that happens when the bot is ready,
# prints success message to console
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
# when the bot recieves a message,
# this is where we define phrases that the bot replies to with a command
@client.event
async def on_message(message):
# checks if the bot is replying to itself
if message.author == client.user:
return
if message.content.startswith('$hello'):
await src.commands.hello.default(message)
if message.content.startswith('$stop'):
await src.commands.stop.default(message, admin, client)
if message.content.startswith('$createuser'):
await src.commands.createuser.default(message)
client.run(token)