Answer the question
In order to leave comments, you need to log in
Why doesn't the bot delete the private channel after it's created?
I wrote this for myself so that there is a bot that creates a channel not at the very end, but after some channel.
As a result, the channel is created but not deleted after the exit
Code:
@bot.event
async def on_voice_state_update(member, before, after):
if after.channel != None:
if after.channel.id == 778594516969586720:
for guild in bot.guilds:
maincategory = discord.utils.get(guild.categories, id=778594516856733696) #категория создания канала
channel2 = await guild.create_voice_channel(
f'╠╣{member.display_name}', #название канала
position=3, #позиция созданного канала (для теста просто уберите этот пункт)
category=maincategory, #категория в которой создастся канал
bitrate=96000 # установить битрейт 96
)
await channel2.set_permissions(member, connect=True, mute_members=True, move_members=True, manage_channels=True) # установить права на канал его создателю
await member.move_to(channel2) # переместить пользователя в этот канал
#часть кода которая должна удалять канал после выхода но этого не делает
def check(x, y):
return len(channel2.members) == 0
await bot.wait_for('voice_channel_update', check = check)
await channel2.delete()
Answer the question
In order to leave comments, you need to log in
You can try this, it's not perfect, needs to be improved
category_id = 778594516856733696 # id категории
make_channel_id = 'id' # id канала, для создания временных каналов
temp = []
@bot.event
async def on_voice_state_update(member, before, after):
if after.channel:
if after.channel.id == make_channel_id:
guild = member.guild # достём guild
# достаём категорию, здесь нужно исправить, но я не помню что и как
# по итогу здесь должен быть объект категории
category = discord.utils.get(guild.categories, id=category_id)
# создаём канал в категории
created_channel = await guild.create_voice_channel(
f'╠╣{member.display_name}',
position=3,
category=category,
bitrate=96000
)
# устанавливаем права
await created_channel.set_permissions(member, connect=True, mute_members=True, move_members=True, manage_channels=True)
# двигаем пользователя в канал
await member.move_to(created_channel)
# чтобы ничего не ждать, сохраняем id канала
temp.append(created_channel.id)
# алгоритм удаления
elif before.channel:
# проверяем id в списке
if before.channel.id in temp:
# если нет пользователей - удаляем
if not before.channel.members:
return await before.channel.delete()
category.create_voice_channel(data)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question