首页 > 解决方案 > 按名称获取不和谐的语音通道 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

标签: pythondiscorddiscord.py

解决方案


要获取频道 ID,您应该阅读本指南,而且每次获取 ID 效率非常低,您可以将频道存储在一个变量中,然后将其删除:

channel = await ctx.guild.create_voice_channel("TEST") # Creates the channel
await channel.delete() # Deletes the channel

推荐阅读