我想记录成员的更新时间,例如新的头像或昵称。我可以将其记录到控制台,但是当我尝试将其发送到频道时会失败。控制台中没有错误。我尝试使用多个帐户和不同的渠道,但仍然没有结果或控制台中的任何错误。
client.on('guildMemberUpdate', async (oldMember, newMember) => {
const guild = newMember.guild;
var Changes = {
unknown: 0,
addedRole: 1,
removedRole: 2,
username: 3,
nickname: 4,
avatar: 5
}
var change = Changes.unknown
var removedRole = ''
oldMember.roles.every(function (value) {
if (newMember.roles.cache.find('id', value.id) == null) {
change = Changes.removedRole
removedRole = value.name
}
})
var addedRole = ''
newMember.roles.every(function (value) {
if (oldMember.roles.cache.find('id', value.id) == null) {
change = Changes.addedRole
addedRole = value.name
}
})
if (newMember.user.username != oldMember.user.username) {
change = Changes.username
}
if (newMember.nickname != oldMember.nickname) {
change = Changes.nickname
}
if (newMember.user.avatarURL() != oldMember.user.avatarURL()) {
change = Changes.avatar
}
var log = guild.channels.cache.get(`755216180603650059`)
if (log != null) {
switch (change) {
case Changes.unknown:
log.send('**[User Update]** ' + newMember)
break
case Changes.addedRole:
log.send('**[User Role Added]** ' + newMember + ': ' + addedRole)
break
case Changes.removedRole:
log.send('**[User Role Removed]** ' + newMember + ': ' + removedRole)
break
case Changes.username:
log.send('**[User Username Changed]** ' + newMember + ': Username changed from ' +
oldMember.user.username + '#' + oldMember.user.discriminator + ' to ' +
newMember.user.username + '#' + newMember.user.discriminator)
break
case Changes.nickname:
log.send('**[User Nickname Changed]** ' + newMember + ': ' +
(oldMember.nickname != null ? 'Changed nickname from ' + oldMember.nickname +
+newMember.nickname : 'Set nickname') + ' to ' +
(newMember.nickname != null ? newMember.nickname + '.' : 'original username.'))
break
case Changes.avatar:
log.send('**[User Avatar Changed]** ' + newMember)
break
}
}
})
答案 0 :(得分:0)
基于Levi_OP的评论
if (a != b) {
//...
}
需要变成:
if (a !== b) {
//...
}