zfbx / zdiscord

A Discord bot that runs in FiveM for the purpose of whitelisting, moderation and utilties using discord.js
Other
210 stars 79 forks source link

Get Discord Profile Picture #97

Closed Simomagy closed 1 year ago

Simomagy commented 1 year ago

Is it possible to make an export to get the Discord profile picture of a user?

zfbx commented 1 year ago

Yeah, from the member object of a user https://discord.js.org/#/docs/discord.js/v13/class/GuildMember specifically member.displayAvatarURL({ format: "png" })

Simomagy commented 1 year ago

Ho provato a farlo ma richiede node.js per forza o c'è un altro modo?

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

const player = discordID

const avatarUrl = player.displayAvatarURL({ format: 'png', dynamic: true, size: 1024 });

console.log(`ID del giocatore: ${discordID}`);
console.log(`URL dell'avatar: ${avatarUrl}`);

client.login('token');
}
zfbx commented 1 year ago

zdiscord uses nodejs under the hood. you don't need all the client. stuff. If you use zdiscord and have it fully setup then you can add to the end of the server.js file ( https://github.com/zfbx/zdiscord/blob/djs/server/server.js ) with the following code

global.exports("getPicture", (identifier) => {
    const member = z.bot.parseMember(identifier);
    return member.displayAvatarURL({ format: "png" }) || "";
});

and use it in any other resource server side with the following exports

-- in a lua script
local picture = exports.zdiscord:getPicture(source);