我目前正在尝试将邀请新成员的用户的姓名添加到我的欢迎消息中! 你可以帮帮我吗?我会在下面留下我的代码,如果你能帮助我,谢谢你!
client.on("guildMemberAdd", async (member) => {
let guild = await client.guilds.cache.get("SERVER ID"); // SERVER ID
let channel = await client.channels.cache.get("CHANNEL ID"); // CHANNEL ID
let emoji = await member.guild.emojis.cache.find(emoji => emoji.name === "eba"); // NOME DO EMOJI
if (guild != member.guild) {
return console.log("Sem boas-vindas pra você! Sai daqui saco pela."); // MENSAGEM EXIBIDA NO CONSOLE
} else {
let embed = await new Discord.MessageEmbed()
.setColor("#fcfcfc")
.setAuthor(member.user.tag, member.user.displayAvatarURL())
.setTitle(`:boom: Boas-vindas :boom:`)
.setImage("https://media.tenor.com/images/c001d9d78724152f00eca4d8ed2e2b9c/tenor.gif")
.setDescription(`**Olá ${member.user}!**\nBem-vindo(a) ao servidor **${guild.name}**!\nVocê é o membro **#${member.guild.memberCount}\n**Compartilhe nosso servidor! :heart:`)
.setFooter("Servidor Espalha Lixo") // Set footer
.setTimestamp();
channel.send(embed);
}
});
答案 0 :(得分:0)
这是有效的;看看这个代码
client.on('guildMemberAdd', member => { //guildMemberAdd event
member.guild.fetchInvites().then(guildInvites => {
// This is the *existing* invites for the guild.
const ei = invites[member.guild.id];
// Update the cached invites for the guild.
invites[member.guild.id] = guildInvites;
// Look through the invites, find the one for which the uses went up.
const invite = guildInvites.find(i => ei.get(i.code).uses < i.uses);
// This is just to simplify the message being sent below (inviter doesn't have a tag property)
const inviter = client.users.get(invite.inviter.id);
channel.send(`${member.user.tag} joined using invite code - ${invite.code} from ${inviter.tag}. Invite was used ${invite.uses} times since its creation.`);
})
});
您可以在 github 的 discordjs-bot-guide 中找到更多信息。
答案 - inviter.tag
来自代码
答案 1 :(得分:0)
没有官方方法可以通过 Discord 的 API 找出谁邀请了某人。人们所做的是存储现有邀请的列表,当有人加入时,将存储的列表与当前列表进行比较,以找出哪个邀请的使用次数增加了。
它并不完美,可能会在有很多人加入的大型服务器中中断。
An Idiot's Guide 网站上有关于此主题的出色指南:https://anidiots.guide/coding-guides/tracking-used-invites