python - 按名称获取不和谐的语音通道 ID
问题描述
我正在尝试创建一个语音频道,然后将所有成员移至该频道。问题是:我不知道如何为 move_to 函数正确获取频道 ID。这是代码:
@bot.command()
async def test(ctx):
await ctx.guild.create_voice_channel("TEST")
test_get = discord.utils.get(ctx.message.guild.channels, name="TEST", type="ChannelType.voice")
await asyncio.sleep(2.0)
for member in ctx.message.guild.members:
try:
await member.move_to(channel=test_get)
except:
pass
使用它,机器人只需从语音通道中删除所有成员,而不是将它们移动到TEST。
解决方案
要获取频道 ID,您应该阅读本指南,而且每次获取 ID 效率非常低,您可以将频道存储在一个变量中,然后将其删除:
channel = await ctx.guild.create_voice_channel("TEST") # Creates the channel
await channel.delete() # Deletes the channel
推荐阅读
- python - 相同的测试数据集在评估时产生不同的准确度
- rest - 使用 Power BI Rest API 将报表导出为 PDF
- ubuntu - 当我不知道显式链接时如何通过终端下载文件?
- flutter - 根据日期显示列表项 - Flutter
- unit-testing - 使用 spock 对 RxJava Flowable 进行单元测试
- swiftui - UIViewControllerRepresentable 永远不应该是一个类有什么原因吗?
- android - 如何使用 GridLayoutManager 在 RecyclerView 中设置不同的边距大小
- android - How can I store the user number like this (1,2,3...)?
- actionscript-3 - How can I pass an arbitrary group of parameters “through” a method?
- vue.js - 如何在 Vue 2 中创建具有验证功能的 VForm 组件,如 Vuetify?