所以我正在使用discord.py
造成不和谐Client
。我正在使用on_voice_state_update
来查看成员的VoiceState
是否更改。
如果特定VoiceChannel
的Category
中没有人,我希望客户端自动删除频道。这是我的代码:
import discord, asyncio
app = discord.Client()
@app.event
async def on_voice_state_update(member_id, before, after):
name2 = str(member_id)
ch = app.get_channel(660213767820410918)
guild = app.get_guild(660213767820410893)
author = member_id
member = after.channel.members
category=guild.get_channel(660213767820410908)
if after.channel == ch:
channel2 = await guild.create_voice_channel(name=(name2+'`s Room'), category=guild.get_channel(660213767820410908) ,user_limit=99)
await author.move_to(channel2)
await channel2.set_permissions(author, manage_channels=True)
if before.channel.members == None:
await delete(before.channel)
但是它不起作用。有人可以帮我吗?
答案 0 :(得分:1)
有一些错误,其中一些是我在您对上一个问题的回答中所解释的。解决方法:
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()