Skip to content
Advertisement

I am trying to make a discord chatbot but I am facing a problem

I have been trying to make a discord chatbot I finished the code “technically” it should work

Here’s my code :

import asyncio, aiohttp, discord, re

class FrostCleverbot(discord.Client):
    async def on_ready(self):
        print('Logging In...')
        await self.change_presence(game=discord.Game(name='chat with me!'))

    async def on_message(self, message):
        if not message.author.bot and (not message.server or message.server.me in message.mentions):
            await self.send_typing(message.channel)
            try:
                input = re.sub('<@!?'+self.user.id+'>', '', message.content).strip()
                params = {'botid': 'f6d4afd83e34564d', 'custid': message.author.id, 'input': input or 'Hello'}
                async with http.get('https://www.pandorabots.com/pandora/talk-xml', params=params) as resp:
                    if resp.status == 200:
                        text = await resp.text()
                        text = text[text.find('<that>')+6:text.rfind('</that>')]
                        text = text.replace('&quot;','"').replace('&lt;','<').replace('&gt;','>').replace('&amp;','&').replace('<br>',' ')
                        await self.send_message(message.channel, text)
                    else:
                        await self.send_message(message.channel, 'Uh oh, I didn't quite catch that!')
            except asyncio.TimeoutError:
                await self.send_message(message.channel, 'Uh oh, I think my head is on backwards!')

print('Starting...')
http = aiohttp.ClientSession()
FrostCleverbot().run('token')

This is the error I’m getting:

Starting...
d:New folderfile.py:26: DeprecationWarning: The object should be created within an async function
  http = aiohttp.ClientSession()
Logging In...
Ignoring exception in on_ready
Traceback (most recent call last):
  File "C:UsersWin10AppDataLocalProgramsPythonPython310libsite-packagesdiscordclient.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "d:New folderfff.py", line 6, in on_ready
    await self.change_presence(game=discord.Game(name='chat with me!'))
TypeError: Client.change_presence() got an unexpected keyword argument 'game'

Any help would be super appreciated, Thank you.

Advertisement

Answer

I’ve not familiar with Dicord’s API, but I’m pretty sure it should be activity instead of game

await self.change_presence(activity=discord.Game(name='chat with me!'))
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement