I’m new to Python and want to make a Twitch chatbot that works like Neuro-sama. It should read chat messages, send them to ChatGPT, and speak the responses out loud. I’ve tried coding it but got stuck with errors. Here’s what I’ve done so far:
import tkinter as tk
import openai
import pyttsx3
from twitchio.ext import commands
class ChatBot(commands.Bot):
def __init__(self):
super().__init__(token='YOUR_TOKEN', prefix='!', initial_channels=['YOUR_CHANNEL'])
self.engine = pyttsx3.init()
openai.api_key = 'YOUR_OPENAI_KEY'
async def event_message(self, message):
if message.echo:
return
response = self.get_ai_response(message.author.name, message.content)
await message.channel.send(f'{message.author.name}, {response}')
self.engine.say(response)
self.engine.runAndWait()
def get_ai_response(self, username, text):
prompt = f'{username} said: {text}\nAI responds:'
response = openai.Completion.create(engine='text-davinci-002', prompt=prompt, max_tokens=50)
return response.choices[0].text.strip()
bot = ChatBot()
bot.run()
I’m getting a TypeError
about multiple values for ‘token’. What am I doing wrong? Also, any tips on improving this code would be great. Thanks!