Skip to main content
 首页 » 编程设计

python "change_presence() takes 1 positional argument but 2 were given"

2024年10月01日7lyhabc

Task exception was never retrieved 
future: <Task finished coro=<on_player_stop() done, defined at /home/pi/Desktop/EbayBot/musicbot/bot.py:413> exception=TypeError('change_presence() takes 1 positional argument but 2 were given',)> 
Traceback (most recent call last): 
 
  File "/usr/local/lib/python3.5/asyncio/tasks.py", line 239, in _step 
    result = coro.send(value) 
 
  File "/home/pi/Desktop/EbayBot/musicbot/bot.py", line 414, in on_player_stop 
    await self.update_now_playing() 
 
  File "/home/pi/Desktop/EbayBot/musicbot/bot.py", line 467, in update_now_playing 
    await self.change_presence(game) 
 
TypeError: change_presence() takes 1 positional argument but 2 were given 

我的代码是:

async def update_now_playing(self, entry=None, is_paused=False): 
    game = None 
 
    if self.user.bot: 
        activeplayers = sum(1 for p in self.players.values() if p.is_playing) 
        if activeplayers > 1: 
            game = discord.Game(name="music on %s servers" % activeplayers) 
            entry = None 
 
        elif activeplayers == 1: 
            player = discord.utils.get(self.players.values(), is_playing=True) 
            entry = player.current_entry 
 
    if entry: 
        prefix = u'\u275A\u275A ' if is_paused else '' 
 
        name = u'{}{}'.format(prefix, entry.title)[:128] 
        game = discord.Game(name=name) 
 
    await self.change_presence(game) 

请您参考如下方法:

如错误消息所述,change_presence 不接受任何位置 参数(self 除外)。所有其他参数必须作为关键字参数传递。

await self.change_presence(game=game) 

参见 the docs . (注意函数签名中的星号。)

change_presence(*, game=None, status=None, afk=False)