Bandwagon Productions
Bandwagon Productions
DIAdiscord.js - Imagine an app
Created by Bandwagon Productions on 8/12/2023 in #djs-questions
Find what role was added/removed with guildMemberUpdate
Hi, I am trying to detect when a role is removed from a user. I currently have the following code:
client.on("guildMemberUpdate", async (old, new_) => {
if(old.roles.cache.size !== new_.roles.cache.size) { // roles have been updated
let currentRole = null
old.roles.cache.forEach((role: Role) => {
if (!new_.roles.cache.has(role.id)) currentRole = role.id
})
if (currentRole) { // the currentRole has been REMOVED
console.log(currentRole.name+" has been removed.")
}
}
})
client.on("guildMemberUpdate", async (old, new_) => {
if(old.roles.cache.size !== new_.roles.cache.size) { // roles have been updated
let currentRole = null
old.roles.cache.forEach((role: Role) => {
if (!new_.roles.cache.has(role.id)) currentRole = role.id
})
if (currentRole) { // the currentRole has been REMOVED
console.log(currentRole.name+" has been removed.")
}
}
})
I thought it would work, and in theory it does, however it doesn't work when the member's roles aren't in the cache (which is quite possible in my use case) so I was wondering if there's any way to detect what role has been removed given that the old's roles may not be cached. Thanks!
6 replies
DIAdiscord.js - Imagine an app
Created by Bandwagon Productions on 6/7/2023 in #djs-questions
Responding to interaction with a video from a URL
Hi, I have a database of videos that are all stored as links (all on the discord CDN and ending in .mp4). I want to respond to a ChatInputCommandInteraction with a video. At the moment I'm doing await i.reply({files: [new Attachment({url: row.content})]}), but that re-uploads the video to the Discord CDN rather than just showing it from the URL, which makes it slower. With images I know you can just provide a url and not have to reupload it, I assume this is possible with videos too? And also Attachment's constructor is private so its not ideal. Is there a "more ideal" way to do this, that's efficient and works?
6 replies