Polarcraft/discordbot/functions/utils.js

24 lines
603 B
JavaScript

const applyUsername = async (user, member) => {
let rawUsername = member.user.globalName;
if (user.useMinecraftUsername && user.minecraftUUID) {
const response = await fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${user.minecraftUUID}`);
const minecraftProfile = await response.json();
rawUsername = minecraftProfile.name;
}
user.rawUsername = rawUsername;
await user.save();
await member.setNickname(rawUsername);
return rawUsername;
};
const getUsername = (user) => {
return user.rawUsername;
};
module.exports = { applyUsername, getUsername };