簡體   English   中英

如何一次性為不和諧服務器中的每個成員分配一個角色 discord.py

[英]How do you give every member in a discord server a role at one time discord.py

我正在嘗試使用此命令為我的服務器中的所有成員分配一個角色,但它似乎不起作用。 它不會將角色賦予所有成員,而只是賦予客戶端。 它也不會在控制台中顯示任何錯誤。

@client.command()
async def assignall(ctx, *, role: discord.Role):
    await ctx.reply("Attempting to assign all members that role...")
    for member in ctx.guild.members:
        await member.add_roles(role)
    await ctx.reply("I have successfully assigned all members that role!")

確保您已從Discord 開發者門戶啟用GUILD_MEMBERS Intent並使用正確的 Intent 初始化您的客戶端。

from discord import Intents
from discord.ext.commands import Bot

client = Bot(intents=Intents.all())

服務器成員意圖

•轉到https://discord.com/developers/applications

•選擇你的機器人

•轉到機器人部分

•向下滾動並啟用所有意圖(從技術上講,您只需要服務器成員的意圖,但如果您做了所有事情,它會對您有所幫助)

在此處輸入圖像描述

•將您的client=commands.Bot(command_prefix="your_prefix")替換為

intents = discord.Intents.default()
intents.message_content = True
client=commands.Bot(command_prefix="your_prefix",intents=intents)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM