简体   繁体   中英

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.

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

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

服务器成员意图

•Go to 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM