如何更改/编辑特定VoiceChannel的名称以显示服务器成员名称

2024-04-24 16:53:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要帮助编辑语音频道的名称。我已经尽我所能去研究并找到答案,但没有人有和我一样的问题:/ 代码:

async def member_count():
            activeServers = bot.servers
            channel = bot.get_channel(549692930294677525) #Collects the voicechannel id I want to change name on
            sum = 0
            for s in activeServers:
                sum += len(s.members)
            await bot.edit_channel(channel, name="MEMBERS: {}".format(int(sum))) #Here am I trying to edit the channels name to "MEMBERS: (number of members in the server atm)"
            await asyncio.sleep(1) #Sleeps for one second before running the code again

    bot.loop.create_task(member_count()) #Creates a loop for the code above

错误消息:

Task exception was never retrieved
future: <Task finished coro=<member_count() done, defined at C:\Users\bjha0\desktop\koding\bot.py:26> exception=AttributeError("'NoneType' object has no attribute 'topic'",)>
Traceback (most recent call last):
  File "C:\Users\bjha0\desktop\koding\bot.py", line 32, in member_count
    await bot.edit_channel(channel, name="MEMBERS: {}".format(int(sum)))
  File "C:\Users\bjha0\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 2007, in edit_channel
    options[key] = getattr(channel, key)
AttributeError: 'NoneType' object has no attribute 'topic'

Tags: thetonameinforbotcountchannel