首页 > 解决方案 > 退出频道时如何删除频道房间 discord.py

问题描述

@bot.event
async def on_voice_state_update(member, before, after):
    if before.channel is None and after.channel is not None:
        await member.guild.system_channel.send(
            "{} into the voice room".format(member.nick)
        )
        channel = await member.guild.create_text_channel('123')

    if before.channel is not None and after.channel is None:
        await member.guild.system_channel.send(
            "{} out of the voice room".format(member.nick)
        )
        channel = await member.guild.delete_text_channel('123')

当我进入语音通道时,机器人会创建一个文本通道,如果我离开语音通道,机器人应该删除文本通道

但是当我出去的时候,bot没有删除频道我该如何修复这个代码?

标签: pythonapidiscorddiscord.py

解决方案


.delete_text_channel() 无效,您必须改用 .delete()

channel = discord.utils.get(member.guild.channels, name="123")
# If channel doesn't exits or channel is not TextChannel
if type(channel) != discord.channel.TextChannel or channel is None: 
    print("No channel found!")
    return
await channel.delete()

推荐阅读