【问题标题】:I am trying to make a discord chatbot but I am facing a problem我正在尝试制作一个不和谐的聊天机器人,但我遇到了问题
【发布时间】:2022-11-03 13:26:19
【问题描述】:

我一直在尝试制作一个不和谐的聊天机器人我完成了“技术上”的代码它应该可以工作

这是我的代码:

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')

这是我得到的错误:

Starting...
d:\New folder\file.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:\Users\Win10\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "d:\New folder\fff.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'

任何帮助将不胜感激,谢谢。

【问题讨论】:

标签: python discord discord.py pandorabots


【解决方案1】:

我不熟悉 Dicord 的 API, 但我很确定应该是活动而不是游戏

await self.change_presence(activity=discord.Game(name='chat with me!'))

【讨论】:

    【解决方案2】:

    将不和谐文件夹移出站点包。 从此位置移动两个文件夹:
    "C:UsersWin10AppDataLocalProgramsPythonPython310libsite-packages

    这个位置也是: "C:UsersWin10AppDataLocalProgramsPythonPython310Lib

    【讨论】:

      猜你喜欢
      • 2021-11-30
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 2023-01-05
      • 2020-01-20
      • 1970-01-01
      • 2017-10-12
      相关资源
      最近更新 更多