本文介紹了如何使用 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 獲取語音頻道的所有成員的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!