本文介绍了打印语音频道成员列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个不和谐的机器人,我需要一个功能来踢掉我频道中的所有成员.我写了这段代码:
i'm coding a discord bot and I need a function that kick all members in my channel. I wrote this code:
@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
返回一个空列表.你能帮助我吗?谢谢你:)
I don't know why canale.members
return an empty list. Can you help me? Thanks you :)
推荐答案
试试这个:
@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
注意:
- 使用此命令时,您需要处于语音通道中.
- 确保机器人有权断开语音通道中存在的成员的连接.
- 确保您在开发者门户中启用了
members
意图. - You need to be in a voice channel while using this command.
- Make sure the bot has the permission to disconnect the members present in the voice channel.
- Make sure you have the
members
intent enabled in your developer portal.
NOTE:
这篇关于打印语音频道成员列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!