admin管理员组文章数量:1429972
client.on('guildMemberAdd', guildMemberAdd => {
console.log("Guild Member joined");
});
I know I have some noob error please help lmao, Just trying to simply detect when a user joins a guild/server and give them a certain role.
client.on('guildMemberAdd', guildMemberAdd => {
console.log("Guild Member joined");
});
I know I have some noob error please help lmao, Just trying to simply detect when a user joins a guild/server and give them a certain role.
Share Improve this question asked Jun 5, 2018 at 17:08 SpectrumSpectrum 211 silver badge2 bronze badges 1- is this all your code or is there more? Just curious. – Matt Pengelly Commented Jun 5, 2018 at 17:19
3 Answers
Reset to default 3A couple ways of adding the roles. Either by id or by role. It's better to know the role ids as it will be faster, however you can look up the role by name as well.
client.on('guildMemberAdd', member => {
// Set the member's roles by id
member.setRoles([/* role id here */]);
// Don't know the role id?
const role = guild.roles.find(role => role.name === 'your role name');
member.addRole(role);
});
I just testing this code and it already works. Just have someone join your channel and you'll see that message in your console.
From the docs on guildMemberAdd
, you can see that the parameter returned in the function is actually a GuildMember
(you put guildMemberAdd
, probably because you didn't know what was passed into that callback).
From there, you can just use Guildmember.setRoles
to give that member / user a specific role.
Try something like this:
// the parameter of the callback function is a `GuildMember` class, so name the variable
// something reasonable like 'guildMember', not 'guildMemberAdd'
client.on('guildMemberAdd', guildMember => {
// Set the member's roles to a single role
guildMember.setRoles(['<your role id>'])
.then(console.log)
.catch(console.error);
});
本文标签: javascriptDiscordJS Detecting when a User joins a guildStack Overflow
版权声明:本文标题:javascript - DiscordJS Detecting when a User joins a guild - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745461619a2659348.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论