首页 > 解决方案 > 在我的情况下,client.user.display 不是一个函数

问题描述

好吧,这里的问题是 displayAvaterURL() 不起作用,我尝试在我的命令中删除一些代码,但似乎没有帮助......而且有点奇怪。我有两个代码块。这是不起作用的命令:(这是 discord.jsv13.1.0)

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed, MessageAttachment } = require('discord.js')

module.exports = {
    data: new SlashCommandBuilder()
        .setName('info')
        .setDescription('Returns info based on input')
        .addSubcommand(subcommand =>
            subcommand
               .setName("user")
               .setDescription("Gets information of a user mentioned")
               .addUserOption(option => option.setName("target").setDescription("The user mentioned")))
        .addSubcommand(subcommand => 
            subcommand
                .setName("server")
                .setDescription("Info about the server")),
    async execute(interaction, client) {
        if (interaction.options.getSubcommand() === "user") {
            const user = interaction.options.getUser("target");
            if (user) {
                const file = new MessageAttachment("./src/images/profile.png");
                const userEmbed = new MessageEmbed()
                    .setTitle(`${user.username}'s Information:'`)
                    .setDescription("This is a description")
                    .setURL("https://twitter.com/@emiluvik")
                    .setAuther("Emiluvik", client.user.displayAvaterURL(), "https://twitter.com/@emiluvik")
                    .setThumbnail(client.user.displayAvaterURL())
                    .addFields(
                        { name: `Username:`,  value: `Username is: ${user.username}`, inline: true},
                        { name: `\u200B`,  value: `\b200B`, inline: true},
                        { name: `Tag:`,  value: `Tag is: #${user.discriminator}`, inline: true}
                    )
                    .setImage("attachement://profile.png")
                    .setTimestamp()
                    .setColor("PURPLE")
                    .setFooter(client.user.tag, client.user.displayAvaterURL())

                await interaction.reply({  embeds: [userEmbed], files: [file] });
            }  else {
                await interaction.reply(`Username: ${interaction.user.username}\nYour ID: ${interaction.user.id}`);
            }
        } else if (interaction.options.getSubcommand() === "server") {
            await interaction.reply(`Server Name: ${interaction.guild.name}\nTotal Members: ${interaction.guild.memberCount}`);
        } else {
            await interaction.reply("No sub command was used.");
        }
    },
};

这是interactionCreate:

module.exports = {
    name: 'interactionCreate',
    async execute(interaction, client) {
        if (!interaction.isCommand()) return;

        const command = client.commands.get(interaction.commandName);

        if (!command) return;

        try {
            await command.execute(interaction, client);
        }  catch (error) {
            console.error(error);
            await interaction.reply({
                content: "There was an error while executing this command!",
                ephemeral: true
            });
        }
    },
};

标签: node.jsdiscorddiscord.js

解决方案


看起来您看不到用户头像,因为您写了 . setAuthor()有错字。你的路线是:.setAuther("Emiluvik", client.user.displayAvaterURL(), "https://twitter.com/@emiluvik")当你需要时.setAuthor("Emiluvik", client.user.displayAvatarURL(), "https://twitter.com/@emiluvik")

你也写client.user.displayAvaterURL()而不是client.user.displayAvatarURL()in 。设置页脚()


推荐阅读