有人可以告诉我为什么这不起作用,它在另一代码中起作用,但是在此代码中不起作用...
代码:
channel.send(`@everyone ${member}`, BoosterEmbed)
错误:
channel.send(`${member}`, BoosterEmbed)
^
ReferenceError: member is not defined
答案 0 :(得分:1)
完整代码:
bot.on('guildMemberUpdate', (oldMember, newMember, member) => {
const channel = newMember.guild.channels.cache.get('705164407008919584');
const BoosterEmbed = new Discord.MessageEmbed()
.setColor('#D605DC')
.setTitle(`${member} just boosted the server wtf`)
.setDescription('Thanks for boost you rich bastard')
.setImage('https://media.tenor.com/images/8db3a7eea372ae195657b4e8ddcbf6d9/tenor.gif')
.setTimestamp()
if (oldMember.roles.cache.size !== newMember.roles.cache.size) {
if (!oldMember.roles.cache.has('713131722409115820') && newMember.roles.cache.has('713131722409115820')) {
channel.send(`@everyone`, BoosterEmbed)
}
}
});
没有错误,但不标记成员
图片 Embed 它发送
答案 1 :(得分:1)
请注意,根据 guildMemberUpdate 的文档如下,仅包含两个参数:
/**
* Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
* Also emitted when the user's details (e.g. username) change.
* @event Client#guildMemberUpdate
* @param {GuildMember} oldMember The member before the update
* @param {GuildMember} newMember The member after the update
*/
您可以在这里找到:https://github.com/discordjs/discord.js/blob/stable/src/client/actions/GuildMemberUpdate.js#L23
请在您的代码中使用 newMember
代替 member
。这应该可以解决您面临的问题。
答案 2 :(得分:-1)
bot.on('guildMemberUpdate', async (oldMember, newMember) => {
const hadRole = oldMember.roles.cache.find(role => role.name === '<ROLE NAME>');
const hasRole = newMember.roles.cache.find(role => role.name === '<ROLE NAME>');
if (!hadRole && hasRole) {
let level = newMember.guild.premiumTier === 0 ? "No Level" : `${newMember.guild.premiumTier}`;
let boost = newMember.guild.premiumSubscriptionCount;
let embed = new Discord.MessageEmbed()
.setThumbnail(newMember.user.displayAvatarURL({ dynamic: true }))
.setTitle(`${newMember.user.username} just boosted the server!`)
.setDescription(`Thank you **<@${newMember.user.id}>** for boosting the server.
Because of you, we are now have **${boost}** boost in total.`)
.setColor("#8f1b85")
.setFooter(`${newMember.guild.name} Level : ${level}`)
newMember.guild.channels.cache.get("<ChannelID>").send(embed);
}
}
)