Discord.js欢迎消息将用户显示为一堆数字,而不是实际的用户名

时间:2020-06-25 19:56:40

标签: javascript node.js discord discord.js

bot.on('guildMemberAdd', member =>{

    const welcomeEmbed = new Discord.MessageEmbed()
    .setTitle(`A new user has joined the server, everyone welcome ${member.user}!`)

    const channel = member.guild.channels.cache.find(channel => channel.name === "welcome-channel");
    if(!channel) return;

    channel.send(welcomeEmbed)
});

2 个答案:

答案 0 :(得分:4)

这是因为您无法在嵌入标题中提及某人,

所以它的作用是将其转换为user_id模式,例如<@id_here>

使用用户类来提及某人为实际消息工作,例如:

message.chanenl.send(`${message.user} hey`);

那会提到用户,并回答“嘿”,

但是就像我之前在嵌入标题中所说的,你不能提及某人。

所以最好的选择是使用他们的用户名:

const welcomeEmbed = new Discord.MessageEmbed()
.setTitle(`A new user has joined the server, everyone welcome ${member.user.username}!`);

答案 1 :(得分:0)

如果您想提及他们,可以使用他们的ID:

const welcomeEmbed = new Discord.MessageEmbed()
    .setTitle(`A new user has joined the server, everyone welcome <@${member.id}>!`);