【问题标题】:how can i delete the channel room when i went out the channel discord.py退出频道时如何删除频道房间 discord.py
【发布时间】:2021-12-21 03:38:00
【问题描述】:
@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 并没有删除频道 如何修复此代码?

【问题讨论】:

    标签: python api discord discord.py


    【解决方案1】:

    .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()
    

    【讨论】:

      猜你喜欢
      • 2018-09-10
      • 2021-01-25
      • 2021-11-08
      • 2020-10-11
      • 2021-10-04
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      相关资源
      最近更新 更多