【问题标题】:Print the list of members in a voice channel打印语音频道中的成员列表
【发布时间】:2020-11-18 10:33:10
【问题描述】:
我正在编写一个不和谐的机器人,我需要一个功能来踢我频道中的所有成员。我写了这段代码:
@client.command()
async def separaci(ctx):
canale = ctx.message.author.voice.channel
utenti = canale.members #This return an empty list
for utente in utenti:
await utente.edit(voice_channel = None)
我不知道为什么canale.members 返回一个空列表。你能帮助我吗?谢谢你:)
【问题讨论】:
标签:
python-3.x
windows
discord
discord.py
discord.py-rewrite
【解决方案1】:
试试这个:
@client.command()
async def separaci(ctx):
if ctx.author.voice: # if the author is connected to a voice channel
canale = ctx.message.author.voice.channel
utenti = canale.members #This return an empty list
for utente in utenti:
await utente.edit(voice_channel = None)
await ctx.send("Kicked all the members from the voice channel!")
else:
await ctx.send("You need to be in a voice channel!")
return
注意:
【解决方案2】:
您必须启用成员意图,并确保在developer portal 中启用它们
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='', intents=intents)
@client.command()
async def separaci(ctx):
channel = ctx.author.voice.channel
members = channel.members