创建私人频道并在不和谐中删除它们
我想制作一个系统,当用户进入私人创建频道时,创建文本通道和语音频道时,创建者可以赋予并剥夺进入私人的权利,并且所有者离开私人,然后在一分钟内删除通道以及数据库中有关它们的数据。我使用mongodb。
我几乎完成了所有代码,但是删除频道的代码不起作用,即检查频道ID。我还想确保如果创作者返回,则取消了30的计时器,但是还有一些更方便的方法来创建此计时器。
@bot.event
async def on_voice_state_update(member, before, after):
if after.channel is not None:
if after.channel.id == 992120556256247808:
guild = bot.get_guild(642681537284014080)
category = discord.utils.get(guild.categories, name='Приват')
v_channel = await guild.create_voice_channel(name=f'Приват ({member.display_name})', category=category)
t_channel = await guild.create_text_channel(name=f'Выдача прав ({member.display_name})', category=category)
await v_channel.set_permissions(member, connect=True, speak=True, view_channel=True, stream=True, kick_members=True, mute_members=True, priority_speaker=True)
role = discord.utils.get(guild.roles, id=642681537284014080)
await v_channel.set_permissions(role, view_channel=False)
await t_channel.set_permissions(role, view_channel=False)
private_post = {
'_id': member.id,
'text_id':t_channel.id,
'voice_id':v_channel.id,
}
private.insert_one(private_post)
await member.move_to(v_channel)
if before.channel == v_channel: #This one and the lines below it don't work
await bot.get_channel(private.find_one({'_id':member.id})['text_id']).send(f'`[PRIVATE]`: {member.mention}, Your private will be deleted in 1 minute!')
time.sleep(60000)
await t_channel.delete()
await v_channel.delete()
roles.delete_one({'_id': member.id})
@bot.command()
async def perm(ctx, member: discord.Member):
if ctx.channel.id == private.find_one({'text_id': ctx.channel.id})['text_id']:
v_channel = bot.get_channel(private.find_one({'text_id': ctx.channel.id})['voice_id'])
await v_channel.set_permissions(member, connect=True, speak=True, view_channel=True, stream=True)
@bot.command()
async def unperm(ctx, member: discord.Member):
if ctx.channel.id == private.find_one({'text_id': ctx.channel.id})['text_id']:
v_channel = bot.get_channel(private.find_one({'text_id': ctx.channel.id})['voice_id'])
await v_channel.set_permissions(member, connect=False, speak=False, view_channel=False, stream=False)
if member in v_channel.members:
await member.move_to(None)
I want to make a system where when a user enters the private creation channel, a text channel and a voice channel are created, in the text the creator can give and take away the rights to enter the private, and if the owner leaves the private, then in a minute the channels should be deleted, as well as data about them from the database. I use MongoDB.
I have done almost all the code, but the code with the removal of channels does not work, namely, checking for the channel id. I also want to make sure that the timer for 30 is canceled if the creator returns, but there is some more convenient way to create this timer.
@bot.event
async def on_voice_state_update(member, before, after):
if after.channel is not None:
if after.channel.id == 992120556256247808:
guild = bot.get_guild(642681537284014080)
category = discord.utils.get(guild.categories, name='Приват')
v_channel = await guild.create_voice_channel(name=f'Приват ({member.display_name})', category=category)
t_channel = await guild.create_text_channel(name=f'Выдача прав ({member.display_name})', category=category)
await v_channel.set_permissions(member, connect=True, speak=True, view_channel=True, stream=True, kick_members=True, mute_members=True, priority_speaker=True)
role = discord.utils.get(guild.roles, id=642681537284014080)
await v_channel.set_permissions(role, view_channel=False)
await t_channel.set_permissions(role, view_channel=False)
private_post = {
'_id': member.id,
'text_id':t_channel.id,
'voice_id':v_channel.id,
}
private.insert_one(private_post)
await member.move_to(v_channel)
if before.channel == v_channel: #This one and the lines below it don't work
await bot.get_channel(private.find_one({'_id':member.id})['text_id']).send(f'`[PRIVATE]`: {member.mention}, Your private will be deleted in 1 minute!')
time.sleep(60000)
await t_channel.delete()
await v_channel.delete()
roles.delete_one({'_id': member.id})
@bot.command()
async def perm(ctx, member: discord.Member):
if ctx.channel.id == private.find_one({'text_id': ctx.channel.id})['text_id']:
v_channel = bot.get_channel(private.find_one({'text_id': ctx.channel.id})['voice_id'])
await v_channel.set_permissions(member, connect=True, speak=True, view_channel=True, stream=True)
@bot.command()
async def unperm(ctx, member: discord.Member):
if ctx.channel.id == private.find_one({'text_id': ctx.channel.id})['text_id']:
v_channel = bot.get_channel(private.find_one({'text_id': ctx.channel.id})['voice_id'])
await v_channel.set_permissions(member, connect=False, speak=False, view_channel=False, stream=False)
if member in v_channel.members:
await member.move_to(None)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
和通道删除。这应该有效:
and the channel deletion. This should work :