This snippet allows you to get a Quora profile's data posted into a channel using a slash command. Make sure to register a command named "quora-profile-info" and add an Option type String using the [command builder](https://autocode.com/tools/discord/command-builder/).
// if you're unsure how to get a user's username, check this answer - https://qr.ae/pGB8Ol
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const quora = require('quora-data-scraper');
let event = context.params.event;
let qUsername = event.data.options[0].value;
// tries to run the block
try {
// returns profile data: https://justpaste.it/82s2w
let User = await quora.fetchUser(`https://quora.com/profile/${qUsername}`);
// gets all of the `name` fields in the `knowledges` array
let aKnowledges = User.knowledges.map(({name}) => name).join(`\n`);
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `Hey <@${event.member.user.id}>, here's info for **${qUsername}**!`,
embeds: [
{
title: `Quora Profile`,
url: `https://quora.com${User.url}`,
fields: [
{
name: `Name`,
value: User.name,
},
{
name: `Biography`,
value: User.biography || 'none',
},
{
name: `Posts`,
value: User.posts || '0',
},
{
name: `Questions`,
value: User.questions || '0',
inline: true,
},
{
name: `Answers`,
value: User.answers || '0',
inline: true,
},
{
name: `Followers`,
value: User.followers || '0',
},
{
name: `Following`,
value: User.following || '0',
},
{
name: `Knowledges`,
value: `${aKnowledges}` || 'none',
},
],
thumbnail: {url: User.avatar},
color: 0xb92b27,
},
],
});
// throws an error and executes the block
} catch (err) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `Hey <@${event.member.user.id}>, no user were found for **${qUsername}**!\nPlease pass a valid username!`,
});
}