我正在使用v12,这是我到目前为止尝试过的:
client.on('guildMemberAdd', (guildMember) => {
guildMember.roles.add(
guildMember.guild.roles.find((r) => r.name === 'Newbie')
);
});
答案 0 :(得分:0)
Discord JS v12引入了管理器的概念,您将不再能够直接使用诸如GuildMember.roles.find
之类的收集方法。现在,在尝试使用收集方法之前,您将必须直接在管理器上请求缓存。 (GuildMember.roles.cache.find
);
client.on("guildMemberAdd", guildMember => { // Detecting when a GuildMember joins the guild.
const Role = guildMember.guild.roles.cache.find(role => role.name == "Newbie"); // Getting the Role by name.
if (!Role) return console.log("Invalid Role"); // Checking if the Role exists.
guildMember.roles.add(Role.id).catch(error => console.log(error)); // Adding the Role to the GuildMember.
});