This snippet allows you to search Roblox users by there username in Discord. It can be used if you need info about some Roblox user. For more Roblox-related projects check my profile.
// 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(' ');
try {
// Make API request
let result = await lib.ropestudio.robloxcore['@0.0.1'].userSearch({
string: `${string}`,
});
let testData = result.information.data[0].name
} catch (e) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ``,
message_reference: {
message_id: `${context.params.event.id}`,
},
embeds: [
{
type: `rich`,
title: `Error occurred!`,
timestamp: `${context.params.event.timestamp}`,
description: ` Unknown error occurred.`,
color: 0x303136,
image: {
url: `https://images.rbxcdn.com/d66ae37d46e00a1ecacfe9531986690a.jpg`,
height: 0,
width: 0,
},
},
],
});
return;
}
// Make API request
let result = await lib.ropestudio.robloxcore['@0.0.1'].userSearch({
string: `${string}`,
});
if (result.information != 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: ` Search result for \*${string}\*.`,
color: 0x303136,
fields: [
{
name: `Username`,
value: result.information.data[0].name,
},
{
name: `Display Name`,
value: result.information.data[0].displayName,
},
{
name: `User ID`,
value: result.information.data[0].id,
},
{
name: `Previous usernames`,
value: !result.information.data[0].previousUsernames
? '\0200B'
: 'No previous usernames',
},
],
thumbnail: {
url: `https://www.roblox.com/headshot-thumbnail/image?userId=${result.information.data[0].id}&width=150&height=150&format=png`,
height: 0,
width: 0,
},
image: {
url: `https://images.rbxcdn.com/d66ae37d46e00a1ecacfe9531986690a.jpg`,
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: ``,
message_reference: {
message_id: `${context.params.event.id}`,
},
embeds: [
{
type: `rich`,
title: `Error occurred!`,
timestamp: `${context.params.event.timestamp}`,
description: ` Unknown error occurred.`,
color: 0x303136,
image: {
url: `https://images.rbxcdn.com/d66ae37d46e00a1ecacfe9531986690a.jpg`,
height: 0,
width: 0,
},
},
],
});
}