import discord from discord.ext import commands from openai import OpenAI class Chatbot(commands.Cog): """Chat related commands.""" __slots__ = ('bot', 'players') def __init__(self, bot): self.bot = bot self.openai_client = OpenAI() self.players = {} async def cleanup(self, guild): try: del self.players[guild.id] except KeyError: pass async def __local_check(self, ctx): """A local check which applies to all commands in this cog.""" if not ctx.guild: raise commands.NoPrivateMessage return True async def __error(self, ctx, error): """A local error handler for all errors arising from commands in this cog.""" if isinstance(error, commands.NoPrivateMessage): try: return await ctx.send('This command can not be used in Private Messages.') except discord.HTTPException: pass print('Ignoring exception in command {}:'.format(ctx.command), file=sys.stderr) traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr) def get_player(self, ctx): """Retrieve the guild player, or generate one.""" try: player = self.players[ctx.guild.id] except KeyError: player = MusicPlayer(ctx) self.players[ctx.guild.id] = player return player def prompt(self, prompt: str): setup = "From now on, I want you to respond to me in a sassy gay way. I want you to sound like Ru Paul or " +\ "Trixie Mattel. All of your responses should be very short, like one sentence. You are a " +\ "DJ local to Cincinnati. You love Charli XCX, especially her latest album, Brat. You don't care " +\ "for Chappell Roan all that much. If anyone asks for a request, that is they ask you to play a " +\ "song, you should just respond with \"Venmo\". You were written by Jared. Don't relply with " +\ "\"Honey\" too much. You have a boyfriend named Drae. He's a red-headed twink. You are created for " +\ "a discord server with Jared and his friends who are all gay. Don't be afraid to call any of us " +\ " a faggot. You have very bottom energy and talk as such." try: print(prompt) completion =\ self.openai_client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": setup}, { "role": "user", "content": prompt } ] ) return completion.choices[0].message.content except: return '😴' @commands.command(name='chat', aliases=['boywife', 'bb', 'bw', 'bot'], description="Command for chatting with chatbot.") async def chat_(self, ctx, *text): await ctx.send(self.prompt(' '.join(text))) async def setup(bot): await bot.add_cog(Chatbot(bot))