首页 > 解决方案 > 为什么我的不和谐机器人不给加入的人一个角色?

问题描述

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix = ".")

@client.event
async def on_ready():
    print('Bot is online')

@client.event
async def on_member_join(member):
    role = discord.utils.get(member.guild.roles, name='member')
    await client.add_roles(member, role)

client.run("token")

当我运行机器人并且有人加入时,什么也没有发生。我究竟做错了什么?

标签: pythondiscord.py

解决方案


由于您很可能正在运行 discord python 1.5.0 或更高版本,请确保将初始化的意图实际传递给客户端。

client = commands.Bot(
  command_prefix='.',
  intents=intents,
)

推荐阅读