我正在尝试快速为人们分配不同的角色,以便给用户留下他们的名字是 Rainbow 的印象(是的,我知道这违反了 TOS),并且我首先在删除角色之前为人们添加角色。但是,在添加角色时,我在这篇文章的标题中收到错误。我已经研究过这个问题并尝试了很多方法来解决它。机器人的角色比分配的角色更高。这是我的代码和输出:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="$")
role_name = "Rainbow Six Seige"
peopleWithRole = []
guild = discord.Guild
@bot.event
async def on_ready():
print("Logged in as")
print(bot.user.name)
print("------")
guild = bot.guilds[0]
colours = [discord.utils.get(guild.roles, name='red'),
discord.utils.get(guild.roles, name='green'),
discord.utils.get(guild.roles, name='blue')
]
role = discord.utils.find(
lambda r: r.name == role_name, guild.roles)
for user in guild.members:
if role in user.roles:
peopleWithRole.append(user)
for color in colours:
for user in peopleWithRole:
await user.add_roles(color)
bot.run("my token")
Run Code Online (Sandbox Code Playgroud)
输出:
Logged in as
test …Run Code Online (Sandbox Code Playgroud)