@@ -81,6 +81,7 @@ async def on_ready():
81
81
print (f"We have logged in as { client .user } " )
82
82
83
83
def run_localagi_thread_history (history , message , thread , loop ):
84
+ agent .channel = message .channel
84
85
def call (thing ):
85
86
return asyncio .run_coroutine_threadsafe (thing ,loop ).result ()
86
87
sent_message = call (thread .send (f"⚙️ LocalAGI starts" ))
@@ -115,6 +116,7 @@ def reasoning_callback(name, reasoning):
115
116
116
117
117
118
def run_localagi_message (message , loop ):
119
+ agent .channel = message .channel
118
120
def call (thing ):
119
121
return asyncio .run_coroutine_threadsafe (thing ,loop ).result ()
120
122
sent_message = call (message .channel .send (f"⚙️ LocalAGI starts" ))
@@ -148,6 +150,7 @@ def reasoning_callback(name, reasoning):
148
150
call (sent_message .edit (content = f"<@{ user .id } > { conversation_history [- 1 ]['content' ]} " ))
149
151
150
152
def run_localagi (interaction , prompt , loop ):
153
+ agent .channel = interaction .channel
151
154
152
155
def call (thing ):
153
156
return asyncio .run_coroutine_threadsafe (thing ,loop ).result ()
@@ -204,8 +207,6 @@ def reasoning_callback(name, reasoning):
204
207
@app_commands .describe (prompt = "Ask me anything!" )
205
208
async def localai (interaction : discord .Interaction , prompt : str ):
206
209
loop = asyncio .get_running_loop ()
207
- agent .loop = loop
208
- agent .channel = interaction .channel
209
210
threading .Thread (target = run_localagi , args = [interaction , prompt ,loop ]).start ()
210
211
211
212
# https://github.com/openai/gpt-discord-bot/blob/1161634a59c6fb642e58edb4f4fa1a46d2883d3b/src/utils.py#L15
@@ -224,16 +225,19 @@ def discord_message_to_message(message):
224
225
return { "role" : "user" , "content" : message .content }
225
226
return None
226
227
228
+ @client .event
229
+ async def on_ready ():
230
+ loop = asyncio .get_running_loop ()
231
+ agent .loop = loop
232
+
227
233
@client .event
228
234
async def on_message (message ):
229
235
# ignore messages from the bot
230
236
if message .author == client .user :
231
237
return
232
238
loop = asyncio .get_running_loop ()
233
- agent .loop = loop
234
239
# ignore messages not in a thread
235
240
channel = message .channel
236
- agent .channel = channel
237
241
if not isinstance (channel , discord .Thread ) and client .user .mentioned_in (message ):
238
242
threading .Thread (target = run_localagi_message , args = [message ,loop ]).start ()
239
243
return
0 commit comments