【问题标题】:How to rename voice channel using discord.py如何使用 discord.py 重命名语音通道
【发布时间】:2021-04-15 21:14:08
【问题描述】:

我的服务器中有一个用于显示日期的语音通道,我正在创建一个应该每分钟更新一次的机器人。我在让机器人重命名机器人时遇到了问题,因为我在 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")

任何帮助将不胜感激。

【问题讨论】:

    标签: python discord bots discord.py discord.py-rewrite


    【解决方案1】:

    您可以使用VoiceChannel.edit() (docs)。

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

    编辑频道
    await vc.edit(name="new-name-goes-here")
    

    您可以使用get_channel() 获取频道的discord.VoiceChannel 实例。

    【讨论】:

      猜你喜欢
      • 2021-11-06
      • 2021-08-26
      • 2021-01-31
      • 2021-12-11
      • 2020-09-24
      • 2021-11-13
      • 2020-06-15
      • 2021-05-10
      • 2019-08-02
      相关资源
      最近更新 更多