1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-07 19:32:34 +01:00

Update Member.ts

This commit is contained in:
Intevel ツ 2021-05-08 13:04:48 +02:00
parent 5482146da4
commit 9870db2841

View File

@ -142,4 +142,33 @@ export async function addRole(user_id: string, guild_id: string, role_id: string
}
export async function removeRole(user_id: string, guild_id: string, role_id: string) {
const user = await getPublicUser(user_id);
const guild = await GuildModel.findOne({ id: guild_id }).exec();
if (!guild) throw new HTTPError("Guild not found", 404);
const role = await RoleModel.findOne({ id: role_id, guild_id: guild_id }).exec();
if (!role) throw new HTTPError("role not found", 404);
var memberObj = await MemberModel.findOneAndUpdate({
id: user_id,
guild_id: guild_id,
}, { $pull: { roles: role_id } }).exec();
if(!memberObj) throw new Error("Internal server error");
emitEvent({
event: "GUILD_MEMBER_UPDATE",
data: {
guild_id: guild_id,
user: user,
roles: memberObj.roles
},
user_id: user_id,
} as GuildMemberUpdateEvent);
}