This snippet allow you to search for Roblox users by there username.
// Authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
await lib.discord.channels['@0.3.1'].typing.create({
channel_id: `${context.params.event.channel_id}`,
});
// Get string what we will search
let message = context.params.event.content;
let string = message.split(' ').slice(1).join(' ');
var result
try {
// Make API request
var result = await lib.robloxcore.users['@0.0.1'].username.search({
username: `${string}`,
});
let testData = result[0].id
} catch (e) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ` Unknown error occurred. \n\n ${e}`,
message_reference: {
message_id: `${context.params.event.id}`,
}
});
return;
}
if (result[0].name != undefined) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ``,
embeds: [
{
type: `rich`,
title: `Roblox user search info`,
description: ` Best result for \**${string}\**.`,
color: 0x303136,
fields: [
{
name: `Username`,
value: result[0].name,
},
{
name: `Display Name`,
value: result[0].displayName,
},
{
name: `User ID`,
value: result[0].id,
},
{
name: `Previous usernames`,
value: !result[0].previousUsernames
? '\0200B'
: 'No previous usernames',
},
],
thumbnail: {
url: `https://www.roblox.com/headshot-thumbnail/image?userId=${result[0].id}&width=150&height=150&format=png`,
height: 0,
width: 0,
},
},
],
message_reference: {
message_id: `${context.params.event.id}`,
},
});
} else {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ` Unknown error occurred.`,
message_reference: {
message_id: `${context.params.event.id}`,
}
});
}