From 996e23dbf61d779eb0b35fb4c7ffcf759c19eb1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TED=20A=2E=20=E2=AD=95?= Date: Wed, 1 May 2024 23:13:25 +0000 Subject: [PATCH] Add main.py --- main.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..c44e60c --- /dev/null +++ b/main.py @@ -0,0 +1,32 @@ +import asyncio +import os +import discord +from characterai import aiocai + +intents = discord.Intents(messages=True, message_content=True, guilds=True) +client = aiocai.Client(CHAR_AI_TOKEN) +char = CHAT_ID + + +class MyClient(discord.Client): + channel = discord.channel + + async def on_message(self, message) -> None: + if message.channel.id == CHANNEL and message.author.id != BOT_ID: + text = await self.push_to_char_ai(message) + print(text) + await self.channel.send(text.text) + + async def push_to_char_ai(self, message) -> str: + async with await client.connect() as chat: + data = await chat.send_message(char=char, + text=f"{message.author.name} says: {message.content}", + chat_id=CHAT_ID) + return data + + async def on_ready(self) -> None: + self.channel = self.get_channel(CHANNEL) + + +bot = MyClient(intents=intents) +bot.run(BOT_TOKEN)