Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

Discord.js How to list the display names of all members with a specific role

I have a command that currently gives a count of how many people have a specific role. That functions properly. I am attempting to make a subcommand of that command that will list the members who have that role and I can get it to list their names as usernames, but I'm looking for it to list it as a display name instead.

This is the code that currently works

let nameList= message.guild.roles.resolve('Role-ID').members.map(m=>m.user.username).join('
');

The "Role-ID is the actual ID in my code. I know that the displayName is a property of the GuildMember but I don't know how to integrate it here. Thoughts?

question from:https://stackoverflow.com/questions/65933977/discord-js-how-to-list-the-display-names-of-all-members-with-a-specific-role

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I figured it out, but instead of deleting my post I figured I would post the solution.

All I needed to do was change .user.username to .displayName

let nameList= message.guild.roles.resolve('Role-ID').members.map(m=>m.user.username).join('
');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...