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中从Azure BLOB存储中读取文件 2022-01-01
 - Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
 - 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
 - PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
 - 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
 - PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
 - 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
 - 包装空间模型 2022-01-01
 - 求两个直方图的卷积 2022-01-01
 - 修改列表中的数据帧不起作用 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				