Discord.js用户信息命令

vc6uscn9  于 2022-09-18  发布在  Java
关注(0)|答案(1)|浏览(195)

我在discord.js中为我的机器人创建了一个用户信息命令,现在我不知道如何获取用户的角色。我尝试查找discord.js文档,但什么也找不到。我已经有了具有以下代码的用户:

const {SlashCommandBuilder} = require('discord.js');
let user;
module.exports = {
    data: new SlashCommandBuilder()
        .setName('user')
        .setDescription('Display info about a selected user')
        .addUserOption(option => option.setName('target').setDescription('The user's information to show')),
    async execute(interaction) {
        user = interaction.options.getUser('target');

        if (user) {
            createEmbed(interaction)
        }
    },
};

function createEmbed(interaction) {

    const embed = {
        // other code
        fields: [

            {
                name: 'Roles',
                value: 'what goes here',
            }

        ],

        //other code
    }

    interaction.reply({
        embeds: [embed]
    })

    return;
}

提前谢谢!

uurity8g

uurity8g1#

const GetUserData = interaction.guild.members.cache.get(USER_ID);
console.log(GetUserData.roles.cache);

Https://discord.js.org/#/docs/discord.js/main/class/GuildMemberRoleManager?scrollTo=cache

相关问题