python - 如何使用 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")
任何帮助将不胜感激。
解决方案
您可以使用VoiceChannel.edit()
(文档)。
如您所见,它有一个name
参数,这听起来像是您需要的。您可以使用编辑频道
await vc.edit(name="new-name-goes-here")
您可以discord.VoiceChannel
使用get_channel()
.
推荐阅读
- reactjs - 如何在 Next.js 中获取来源或域名
- sass - phpstorm 编译 sass 缩小
- swift - 为什么 for 循环中并发队列上的 .async 与 DispatchQueue.concurrentPerform 的行为不同?
- python - 来自 csv 文件的列中的中间数据
- moodle - Moodle Formulas中的JSXGraph有两个板:绑定到输入字段不起作用
- swift - 无法快速将文件写入桌面
- reactjs - 对 react + redux 的开玩笑测试在道具中说未定义的值
- python - JiTCDDE 集成问题
- swiftui - @Published 属性未从嵌套视图模型更新视图 - SwiftUI
- c - C浏览器在网页上显示服务器套接字响应,但网页一直在加载