-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmessage_handler.py
More file actions
37 lines (28 loc) · 1.28 KB
/
message_handler.py
File metadata and controls
37 lines (28 loc) · 1.28 KB
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
from commands.base_command import BaseCommand
import discord
# This, in addition to tweaking __all__ on commands/__init__.py,
# imports all classes inside the commands package.
from commands import *
import settings
# Register all available commands
COMMAND_HANDLERS = {c.__name__.lower(): c()
for c in BaseCommand.__subclasses__()}
###############################################################################
async def handle_command(command, args, message, bot_client):
# Check whether the command is supported, stop silently if it's not
# (to prevent unnecesary spam if our bot shares the same command prefix
# with some other bot)
if command not in COMMAND_HANDLERS:
return
print(f"{message.author.name}: {settings.COMMAND_PREFIX[0]}{command} "
+ " ".join(args))
# Retrieve the command
cmd_obj = COMMAND_HANDLERS[command]
if cmd_obj.params and len(args) < len(cmd_obj.params):
err = discord.Embed(
title = "Oops, you seem to have used the command incorrectly, try using ap!help for the proper command syntax.",
colour = discord.Colour.red()
)
await message.channel.send(content = "", embed = err)
else:
await cmd_obj.handle(args, message, bot_client)