-
Notifications
You must be signed in to change notification settings - Fork 2
/
constantine.py
40 lines (31 loc) · 1.13 KB
/
constantine.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
import discord # Discord API Wrapper
import json # JSON De/Encoder
from handler import CommandHandler # Handles all the commands
# Read the config as json object
with open('config.json') as data_file:
config = json.load(data_file)
# Get the different options from the json object
prefix = config['prefix']
discordtoken = config['discordtoken']
# Create new client and handler instance
client = discord.Client()
handler = CommandHandler(prefix , client)
# Log to console when the client is started
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
# Fires every time a new message is received
@client.event
async def on_message(message):
# Make sure we don't handle messages that we sent, that would be VERY inefficient.
if message.author == client.user:
return
# This easy test can be done here, makes it clear that the handler is handling commands and NOT checking if they
# are commands
if message.content.startswith(prefix):
await handler.handle(message)
# Connect the client to Discord
client.run(discordtoken)