当有人更改个人资料图片时,我试图在频道中发送消息,但它不起作用,因为来自 oldUser 和 newUser 的 url 总是相同的(新头像 url 两次),我对昵称更改做了类似的事情它实际上运行良好..
private func recursion(node: Syntax) -> String {
for child in node.children {
if let tokenKind = (child as? TokenSyntax)?.tokenKind, tokenKind == .structKeyword {
// if type(of: child) == StructDeclSyntax.self {
print ("yeah")
}
recursion(node: child)
}
}
let input = """
public struct cmd_deleteEdge<E: VEdge> : EdgeCommand {
public var keyEquivalent = KeyEquivalent.none
public let title = "Delete Edge"
public let id = "deleteEdge"
public let toolTip = "Delete selected Edge"
public let icon = Icon.delete
//receivers
public let edge: E
public init(edge: E) {
self.edge = edge
}
public func execute() throws -> ActionResult {
edge.deleteYourself()
return .success("deleted edge")
}
}
"""
public func convert(structText: String) throws -> String {
let sourceFile = try SyntaxParser.parse(source: structText)
let result = recursion(node: Syntax(sourceFile))
return result
}
try convert(structText: input)
修改头像后登录,oldMember和newMember头像url是一样的(两次是新头像url):
bot.on("guildMemberUpdate", (oldMember, newMember) => {
//checks if the change is the nickname
if (oldMember.displayName != newMember.displayName) {
console.log(`(NEW ACTIVITY): @${oldMember.user.username} changed username. @${oldMember.displayName} was the username before update, @${newMember.displayName} is the username after update`);
//build embed
messages.usernameUpdate(bot, oldMember, newMember);
}
console.log(oldMember.user.displayAvatarURL());
console.log(newMember.user.displayAvatarURL());
//checks if the change is the profile picture
if (oldMember.user.displayAvatarURL() != newMember.user.displayAvatarURL()) {
console.log(`(NEW ACTIVITY): @${newMember.user.username} updated profile picture`);
//build embed
messages.photoUpdate(bot, oldMember, newMember);
}
});
答案 0 :(得分:0)
我认为它是一个 known issue,它的工作原理是这样的,因为如果用户信息发生更改,Discord 会同时发送 PRESENCE_UPDATE
和 GUILD_MEMBER_UPDATE
。
首先,在 PRESENCE_UPDATE
discord.js 确定更改并将其应用于缓存,在 GUILD_MEMBER_UPDATE
上,底层用户已经从 PRESENCE_UPDATE
更改,因此旧用户无法与旧成员一起发射。因此,每次用户更新时,GUILD_MEMBER_UPDATE
不会保存“旧”数据,只保存更新后的版本。这就是 oldMember.user.displayAvatarURL()
与 newMember.user.displayAvatarURL()
相同的原因。
我知道这可能不是您期望的答案。