首页 > 解决方案 > 如何使用 discord.py 重命名语音通道

问题描述

我的服务器中有一个用于显示日期的语音通道,我正在创建一个应该每分钟更新一次的机器人。我在让机器人重命名机器人时遇到了问题,因为我在 discord.py 方面不是很有经验。这是代码:

import asyncio, os

client = commands.Bot(command_prefix='!')

os.system('cls' if os.name == 'nt' else 'clear')

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

async def background_task():
    await client.wait_until_ready()
    while not client.is_closed():
        #Rename Voice Channel
        await asyncio.sleep(60)

client.loop.create_task(background_task())
client.run("TOKEN")

任何帮助将不胜感激。

标签: pythondiscordbotsdiscord.pydiscord.py-rewrite

解决方案


您可以使用VoiceChannel.edit()文档)。

如您所见,它有一个name参数,这听起来像是您需要的。您可以使用编辑频道

await vc.edit(name="new-name-goes-here")

您可以discord.VoiceChannel使用get_channel().


推荐阅读