问题
Turning the translator around can make English seem unnatural.
If there are no users on the voice channel, the program will fail.
So I would like to check if there are users on the voice channel and know the function of discord.py which does the bool or other reset type.
elif message.content.startswith('>보이스'):
tmp = str(message.author.display_name).split()
tmp = tmp[2].split('(')
if(len(tlst) >= 10 ):
for i in range(0,len(lst)):
if(tlst[4] == 3):
print(i)
vnum = tlst[i]
vch = 'Duo_'+ str(vnum)
print(vch)
if(tmp[0] == lst[i]) == True:
embed = discord.Embed(title="이동완료!", color=0x00ff00)
await client.send_message(message.channel, embed=embed)
channel = discord.utils.find(lambda x: x.name == vch, message.server.channels)
await client.move_member(message.author , channel)
elif(tlst[4] == 2):
vnum = tlst[i]
vch = 'Squad_'+ str(vnum)
if(tmp[0] == lst[i]) == True:
embed = discord.Embed(title="이동완료!", color=0x00ff00)
await client.send_message(message.channel, embed=embed)
channel = discord.utils.find(lambda x: x.name == vch, message.server.channels)
await client.move_member(message.author , channel)
else:
embed = discord.Embed(title="띠용", description="팀 5는 보이스 기능이 없습니다.", color=0x00ff00)
await client.send_message(message.channel, embed=embed)
else:
embed = discord.Embed(title="띠용", description="팀을 먼저 짜주세요~", color=0x00ff00)
await client.send_message(message.channel, embed=embed)
回答1:
You can check the length of Channel.voice_members, which will be a list of members in the channel.
来源:https://stackoverflow.com/questions/53904189/can-i-check-if-there-is-a-user-in-the-voice-channel