How to get all members of a voice-channel with discord.py(如何使用 discord.py 获取语音频道的所有成员)
问题描述
我有问题,如果我将所有成员作为特定语音频道的 Meber 的对象.我只得到一个空列表.
I have the problem, if I will get all members as an object of Meber of a specific Voice-channel. I only get a empty list back.
这是我的代码:
@bot.command(name='random')
async def nine_nine(ctx, amount_of_groups: int):
this_guild = ctx.guild
sender = ctx.message.author
#Es wird geschaut, in welchem Channel sich der Schreiber befindet
try:
voice_channel = ctx.message.author.voice.channel
print(voice_channel)
except AttributeError:
await ctx.send("Du bist in keinem Voice-Channel")
return
#Alle anderen Mitglieder aus dem Kanal werden ermittelt und in eine Liste geschrieben
this_category = voice_channel.category
member_list = voice_channel.members # <-- This only returns an empty List
print(member_list)
print(this_category)
#Die Mitglieder werden gemischt
random.shuffle(member_list)
#Die Mitglieder werden in gleichgroße Gruppen aufgeteilt
avg = len(member_list) / float(amount_of_groups)
out = []
last = 0.0
while last < len(member_list):
out.append(member_list[int(last):int(last + avg)])
last += avg
print(out)
for group in range(0, amount_of_groups):
new_channel = await this_guild.create_voice_channel(name=f'Gruppe{group+1}', category=this_category)
for member in range(len(out[group])):
try:
await out[group][member].move_to(new_channel)
except:
print("F")
print(out[group][member])
我该如何解决这个问题?
How can I fix this Problem?
推荐答案
你必须像这样在 bot = ... 之前启用 Intents.members:
You have to enable Intents.members like this before bot = ... :
intents = discord.Intents.default()
intents.members = True
并更新 bot = .. 以包含参数 intents=intents.
and update the bot = .. to include the argument intents=intents.
您还必须在您的应用程序站点中启用不和谐的成员意图(
Also you have to enable member intents in your application site in discord (go here, click on your bot, click on bot at the sidebar and enable them.):
参考资料:
discord.Intents.members
这篇关于如何使用 discord.py 获取语音频道的所有成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 discord.py 获取语音频道的所有成员
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
