node.js - 在我的情况下,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
});
}
},
};
解决方案
看起来您看不到用户头像,因为您写了 . 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 。设置页脚()
推荐阅读
- graphql - 有没有办法使用 graphql 订阅将数据与聚合一起获取?
- node.js - 当 Node.js API 出现故障时,是否可以阻止 nginx 响应?
- java - 如何在没有 GMT 的情况下使用 java.time.ZonedDateTime 和 format.DateTimeFormatter?
- java - TreeSet.lower() 方法在使用显式比较器构造函数时未返回所需的输出
- postgresql - 气流 2.1.3 使用 pgbouncer 解决 postgresql 问题
- xamarin.forms - Xamarin Android DisplayPromptAsync 无法禁止建议
- azure - 将 Function App 计划从消费升级到标准时出现意外错误。但只对某些人
- java - AWS lambda 有效,但网关无效
- regex - 通过 RegEx 解析具有不同引号的输入字符串
- c# - 如何使用自定义图标导出 exe?