Browse Source

added decorator to notify if inputted command was wrong

tenessy0570 3 years ago
parent
commit
90dbc11464
2 changed files with 11 additions and 3 deletions
  1. 3 3
      __init__.py
  2. 8 0
      decorators.py

+ 3 - 3
__init__.py

@@ -1,7 +1,7 @@
 import discord
 import discord
 from os import environ
 from os import environ
 import environment_vars
 import environment_vars
-from decorators import author_is_not_bot
+from decorators import author_is_not_bot, notify_if_wrong_command
 from img_urls import good_face_url
 from img_urls import good_face_url
 from utils import on_ready_print, receive_message_then_send, get_commands_from_file
 from utils import on_ready_print, receive_message_then_send, get_commands_from_file
 
 
@@ -15,6 +15,7 @@ class MyClient(discord.Client):
         on_ready_print(self)
         on_ready_print(self)
 
 
     @author_is_not_bot
     @author_is_not_bot
+    @notify_if_wrong_command
     async def on_message(self, message):
     async def on_message(self, message):
         if await receive_message_then_send(message, "ping", "pong"):
         if await receive_message_then_send(message, "ping", "pong"):
             return
             return
@@ -33,8 +34,7 @@ class MyClient(discord.Client):
             await message.channel.send(embed=image_to_send)
             await message.channel.send(embed=image_to_send)
             return
             return
 
 
-        await message.channel.send('I cant understand you :(\nType !help for available command list')
-        return
+        return True
 
 
 
 
 bot_token = environ.get('bot_token')
 bot_token = environ.get('bot_token')

+ 8 - 0
decorators.py

@@ -4,3 +4,11 @@ def author_is_not_bot(func):
             return None
             return None
         return await func(self, message, *args, **kwargs)
         return await func(self, message, *args, **kwargs)
     return wrapper
     return wrapper
+
+
+def notify_if_wrong_command(func):
+    async def wrapper(self, message, *args, **kwargs):
+        function_return = func(self, message, *args, **kwargs)
+        if await function_return:
+            await message.channel.send('I cant understand you :(\nType !help for available command list')
+    return wrapper