forked from rohan-achar/RPG-Helper-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord_bot.py
executable file
·41 lines (33 loc) · 1.11 KB
/
discord_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
'''Runs the Discord RPG Helper bot.'''
import argparse
import os
import discord
from rpg_helper import RPGHelper
class DiscordClient(discord.Client):
'''Client that handles discord messages.'''
def __init__(self, helper):
super().__init__()
self.rpg_helper = helper
async def on_ready(self):
'''Logging the bot login.'''
print("Logged on as", self.user)
async def on_message(self, message):
'''Observing each message and responding if needed.'''
if message.author == self.user:
return
userid = message.author.id
resp = self.rpg_helper.handle_command(userid, message.content)
if resp:
await message.channel.send(resp)
if __name__ == "__main__":
PARSER = argparse.ArgumentParser()
PARSER.add_argument(
"-l", "--load",
default="seonstra",
help="Load a game by default on start")
ARGS = PARSER.parse_args()
while True:
try:
DiscordClient(RPGHelper(ARGS.load)).run(os.environ["discord_token"])
except Exception:
print ("Exception was caught")