[英]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.