-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord-chatbot.ts
40 lines (35 loc) · 951 Bytes
/
discord-chatbot.ts
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
38
39
40
import { Client, Message } from "https://deno.land/x/harmony/mod.ts"
import { TextAssistant } from "@robbie-wasabi/llmonade"
const client = new Client({
intents: [
"GUILDS",
"DIRECT_MESSAGES",
"GUILD_MESSAGES",
],
token: Deno.env.get("DISCORD_TOKEN"),
})
const assistant = TextAssistant.new()
.withModel("gpt-4o")
.withInstructions(
"You are a helpful assistant that can answer questions and help with tasks.",
)
.onThinking(() => {
console.log("thinking...")
})
.onError((error) => {
console.error(error)
})
client.on("ready", () => {
console.log(`Ready! User: ${client.user?.tag}`)
})
client.on("messageCreate", async (msg: Message): Promise<void> => {
if (msg.content.toLowerCase().includes("!llmonade")) {
const reply = await assistant.chat(msg.content)
if (!reply) {
console.error("No reply from assistant")
return
}
msg.channel.send(reply)
}
})
client.connect()