aboutsummaryrefslogtreecommitdiff
path: root/discord/ext/commands/bot.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-05 01:11:52 -0500
committerRapptz <[email protected]>2016-01-05 01:11:52 -0500
commit51186c3ca450a70547b6f71157ecd55aad25841d (patch)
treefc0015bce7dda68c37b769952f306437b74ed61c /discord/ext/commands/bot.py
parentAdd basic example bot showcasing the commands ext module. (diff)
downloaddiscord.py-51186c3ca450a70547b6f71157ecd55aad25841d.tar.xz
discord.py-51186c3ca450a70547b6f71157ecd55aad25841d.zip
[commands] Add CommandNotFound error.
Diffstat (limited to 'discord/ext/commands/bot.py')
-rw-r--r--discord/ext/commands/bot.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py
index a788f670..35b1d149 100644
--- a/discord/ext/commands/bot.py
+++ b/discord/ext/commands/bot.py
@@ -31,6 +31,7 @@ import inspect
from .core import GroupMixin
from .view import StringView
from .context import Context
+from .errors import CommandNotFound
class Bot(GroupMixin, discord.Client):
"""Represents a discord bot.
@@ -203,18 +204,21 @@ class Bot(GroupMixin, discord.Client):
view.skip_ws()
invoker = view.get_word()
+ tmp = {
+ 'bot': self,
+ 'invoked_with': invoker,
+ 'message': message,
+ 'view': view,
+ }
+ ctx = Context(**tmp)
+ del tmp
if invoker in self.commands:
command = self.commands[invoker]
- tmp = {
- 'bot': self,
- 'invoked_with': invoker,
- 'message': message,
- 'view': view,
- 'command': command
- }
- ctx = Context(**tmp)
- del tmp
+ ctx.command = command
yield from command.invoke(ctx)
+ else:
+ exc = CommandNotFound('Command "{}" is not found'.format(invoker))
+ self.dispatch('command_error', exc, ctx)
@asyncio.coroutine
def on_message(self, message):