![](/img/trans.png)
[英]How to add a pause between a discord.py bot joining a voice-channel?
[英]How to get all members of a voice-channel with discord.py
我有問題,如果我將所有成員都作為特定語音通道的 Meber 的 object。 我只得到一個空列表。
這是我的代碼:
@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])
我該如何解決這個問題?
您必須在bot =...
之前啟用Intents.members
:
intents = discord.Intents.default()
intents.members = True
並更新bot =..
以包含參數intents=intents
。
此外,您必須在 discord 的應用程序站點中啟用成員意圖(此處為 go ,單擊您的機器人,單擊側邊欄上的bot
並啟用它們。):
參考:
您是否啟用了意圖? 如果你沒有,go 到 discord.com/developers/dashboard,select 你的機器人並啟用意圖。 之后在您的代碼中啟用意圖:
intents = discord.Intents.default()
intents.Member = True
bot = commands.Bot(command_prefix="yourprefix", intents=intents)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.