简体   繁体   English

如何一次性为不和谐服务器中的每个成员分配一个角色 discord.py

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

I'm trying to give all members in my server a role with this command, but it doesn't seem to work.我正在尝试使用此命令为我的服务器中的所有成员分配一个角色,但它似乎不起作用。 It doesn't give the role to all the members, but just to the client.它不会将角色赋予所有成员,而只是赋予客户端。 It also doesn't show any errors in the console.它也不会在控制台中显示任何错误。

@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!")

Ensure that you have enabled the GUILD_MEMBERS Intent from your Discord Developer Portal and initialized your client with the proper intents.确保您已从Discord 开发者门户启用GUILD_MEMBERS Intent并使用正确的 Intent 初始化您的客户端。

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

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

服务器成员意图

•Go to https://discord.com/developers/applications •转到https://discord.com/developers/applications

•Select your bot •选择你的机器人

•Go to the bot section •转到机器人部分

•Scroll down and enable all the intents(Technically you need only server members' intent but if you do all it will help you) •向下滚动并启用所有意图(从技术上讲,您只需要服务器成员的意图,但如果您做了所有事情,它会对您有所帮助)

在此处输入图像描述

•Replace your client=commands.Bot(command_prefix="your_prefix") to •将您的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