Spaces:
Runtime error
Runtime error
if message.channel.id == 1162396480825462935:
Browse files- discord_bot/client/client.py +33 -28
discord_bot/client/client.py
CHANGED
@@ -98,33 +98,38 @@ class DiscordClient(discord.Client):
|
|
98 |
|
99 |
|
100 |
async def on_message(self, message):
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
if self.enable_commands and message.content.startswith('!'):
|
110 |
-
if message.content == '!clear':
|
111 |
-
await message.channel.purge()
|
112 |
return
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
128 |
)
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
|
100 |
async def on_message(self, message):
|
101 |
+
if message.channel.id == 1162396480825462935:
|
102 |
+
"""
|
103 |
+
Callback function to be called when a message is received.
|
104 |
+
|
105 |
+
Args:
|
106 |
+
message (discord.Message): The received message.
|
107 |
+
"""
|
108 |
+
if message.author == self.user:
|
|
|
|
|
|
|
109 |
return
|
110 |
+
|
111 |
+
"""
|
112 |
+
if self.enable_commands and message.content.startswith('!'):
|
113 |
+
if message.content == '!clear':
|
114 |
+
await message.channel.purge()
|
115 |
+
return
|
116 |
+
"""
|
117 |
+
|
118 |
+
|
119 |
+
last_messages = await self.get_last_messages(message)
|
120 |
+
context = '\n'.join(last_messages)
|
121 |
+
|
122 |
+
logger.info('Received message: {0.content}'.format(message))
|
123 |
+
response = self.qa_engine.get_response(
|
124 |
+
question=message.content,
|
125 |
+
messages_context=context
|
126 |
)
|
127 |
+
logger.info('Sending response: {0}'.format(response))
|
128 |
+
try:
|
129 |
+
await self.send_message(
|
130 |
+
message,
|
131 |
+
response.get_answer(),
|
132 |
+
response.get_sources_as_text()
|
133 |
+
)
|
134 |
+
except Exception as e:
|
135 |
+
logger.error('Failed to send response: {0}'.format(e))
|