【问题标题】:I want to delete only the voice channels in one category我只想删除一个类别中的语音通道
【发布时间】:2020-07-29 15:56:28
【问题描述】:

这是我的代码:

import discord, asyncio
    
app = discord.Client()
    
@app.event
async def on_voice_state_update(member, before, after):
    username = str(member)
    guild = app.get_guild(660213767820410893)
    ch = guild.get_channel(660213767820410918)
    category = guild.get_channel(660213767820410908)
    
    if after.channel == ch:
        channel = await guild.create_voice_channel(
                name=username+"`s Room",
                category=category,
                user_limit=99
            )
        await member.move_to(channel)
        await channel.set_permissions(member, manage_channels=True)
    if not before.channel.members and before.channel != ch:
        await before.channel.delete()

我只想删除一个类别中的语音频道。目前,所有频道都已删除。

【问题讨论】:

  • 您应该检查频道类别是否与所述类别匹配
  • 匹配 MatchesMatches
  • 请在下面查看我的答案。如果有帮助,别忘了点赞并接受。

标签: python python-3.x discord.py


【解决方案1】:

如果 VoiceChannelcategory 中,您是否只想删除它?如果是,您可以在最后一个 if 块中添加条件:before.channel.category == category

import discord, asyncio
    
app = discord.Client()
    
@app.event
async def on_voice_state_update(member, before, after):
    username = str(member)
    guild = app.get_guild(660213767820410893)
    ch = guild.get_channel(660213767820410918)
    category = guild.get_channel(660213767820410908)
    
    if after.channel == ch:
        channel = await guild.create_voice_channel(
                name=username+"`s Room",
                category=category,
                user_limit=99
            )
        await member.move_to(channel)
        await channel.set_permissions(member, manage_channels=True)

    b_channel = before.channel
    if b_channel: # If the user was connected to a voice channel before 
        if not b_channel.members and b_channel != ch and b_channel.category == category:
            await b_channel.delete()

【讨论】:

    猜你喜欢
    • 2020-11-07
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    • 2017-05-14
    • 1970-01-01
    相关资源
    最近更新 更多