我需要帮助来编辑语音通道的名称。我已经尽力研究并找到了答案,但是没有人遇到与我相同的问题:/ 代码:
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'
答案 0 :(得分:0)
我发现这至少对我来说是完美的。
异步0.16.12:
constexpr int value = min(x, y + 1);
constexpr int const& ref2 = value;
重写1.3.3:
async def members():
activeServers = bot.servers
channel = bot.get_channel("<channel id here>")
sum = 0
for s in activeServers:
sum += len(s.members)
await bot.edit_channel(channel, name="❎ MEMBERS: {} ❎".format(int(sum)))
await asyncio.sleep(1)
@bot.event
async def on_member_join(member):
await members()
@bot.event
async def on_member_remove(member):
await members()