From 6d77b3bee34cb9ff760317ad8e340e14a37b6bd8 Mon Sep 17 00:00:00 2001 From: Taken Date: Sat, 8 Apr 2023 14:33:08 +0200 Subject: [PATCH] First move to functions --- commands-testing/functest.js | 49 ++++++++++++++++++++++++++++++++++++ utils/functions.js | 14 +++++++++++ 2 files changed, 63 insertions(+) create mode 100644 commands-testing/functest.js create mode 100644 utils/functions.js diff --git a/commands-testing/functest.js b/commands-testing/functest.js new file mode 100644 index 0000000..ae97c49 --- /dev/null +++ b/commands-testing/functest.js @@ -0,0 +1,49 @@ +const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); +const getuuid = require('../utils/functions'); + +module.exports = { + name: 'functest', + description: 'Test command for the bot.', + type: 'slash', + + data: new SlashCommandBuilder() + .setName('functest') + .setDescription('Test command for the bot.') + .addStringOption(option => + option + .setName('test') + .setDescription('Test option.')) + .addStringOption(option => + option + .setName('test2') + .setDescription('Test option.')) + .addStringOption(option => + option + .setName('test3') + .setDescription('Test option.')) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .setDMPermission(false), + + async execute(interaction) { + + const test = interaction.options.getString('test'); + const test2 = interaction.options.getString('test2'); + const test3 = interaction.options.getString('test3'); + + const uuid = await getuuid(test); + + if (uuid === null) { + await interaction.reply({ + content: 'Invalid username.', + ephemeral: true + }); + return + } + + await interaction.reply({ + content: uuid, + ephemeral: true + }); + + } +}; \ No newline at end of file diff --git a/utils/functions.js b/utils/functions.js new file mode 100644 index 0000000..d716a84 --- /dev/null +++ b/utils/functions.js @@ -0,0 +1,14 @@ +const fetch = require("axios"); + +async function getuuid(ign) { + const mojangAPI = "https://api.mojang.com/users/profiles/minecraft/" + + try { + const user = await fetch(mojangAPI + ign) + return user.data.id; + } catch (error) { + return null; + } +} + +module.exports = getuuid; \ No newline at end of file