Reputation: 37
so I have a huge problem with people joining my server with a hoisted name "! Name" which puts them at the top of the member's list, and they can advertise their servers. I am trying to change their nickname to something random when they join. I am using discord.js. I think it would be something like "message.member.setNickname" but I could be wrong, if you can help it would be appreciated!
Upvotes: 0
Views: 1395
Reputation: 8412
To detect incoming users, you should listen to the guildMemberAdd
event, which passes a GuildMember
as a parameter. GuildMembers
don't have a username
property, so you'll have to use GuildMember#user
to convert it to a User
, and then check User#username
.
If the username starts with a !
, you can use GuildMember#setNickname
to change it.
client.on('guildMemberAdd', (member) => {
if (member.user.username.startsWith('!')) {
member.setNickname('...');
// code...
}
});
It might also be a good idea to listen to the guildMemberUpdate
event to see if a member ever changes their nickname after joining to something you wouldn't want.
Upvotes: 1