我在Discord.js v12.2.0上的Discord机器人上设置服务器日志,我目前正在尝试设置角色日志。我在互联网上翻找了一下,我只能在旧版本的Discord.js上找到解决方案,这显然在v12.2.0上不起作用。我已经设置了guildMemberUpdate事件来记录昵称更改,但我不知道如何为角色执行此操作。这可能只是超级简单,但我不知道我会怎么做。
以下是我目前为止的代码:
client.on('guildMemberUpdate', (oldMember, newMember) => {
if (!oldMember.nickname && newMember.nickname) {
const membernewnicklog = new Discord.MessageEmbed()
.setAuthor(`${newMember.user.tag}`, `${newMember.user.displayAvatarURL({ format: "png", dynamic: true })}`)
.setDescription(`**${newMember} nickname added**`)
.setFooter(`${newMember.user.username}'s ID: ${newMember.id}`)
.setTimestamp()
.setColor('#ffff00')
.addField("New nickname", newMember.nickname)
client.channels.cache.get('736996028787589201').send(membernewnicklog);
return;
}
if (oldMember.nickname && !newMember.nickname) {
const memberremovenicklog = new Discord.MessageEmbed()
.setAuthor(`${oldMember.user.tag}`, `${oldMember.user.displayAvatarURL({ format: "png", dynamic: true })}`)
.setDescription(`**${oldMember} nickname removed**`)
.setFooter(`${oldMember.user.username}'s ID: ${oldMember.id}`)
.setTimestamp()
.setColor('#f04747')
.addField("Old nickname", oldMember.nickname)
client.channels.cache.get('736996028787589201').send(memberremovenicklog);
return;
}
if (oldMember.nickname && newMember.nickname) {
const memberchangednicklog = new Discord.MessageEmbed()
.setAuthor(`${newMember.user.tag}`, `${newMember.user.displayAvatarURL({ format: "png", dynamic: true })}`)
.setDescription(`**${newMember} nickname changed**`)
.setFooter(`${newMember.user.username}'s ID: ${newMember.id}`)
.setTimestamp()
.setColor('#ff4500')
.addField("Before", oldMember.nickname)
.addField("After", newMember.nickname);
client.channels.cache.get('736996028787589201').send(memberchangednicklog);
return;
}
});
我的目标是https://imgur.com/a/FRbTpGQ(来自另一个bot的示例)
任何帮助将是超级感激。谢谢!
1条答案
按热度按时间cbjzeqam1#