Adding User App Support

This commit is contained in:
dlinux-host
2024-10-03 18:00:03 -04:00
parent 26621c9866
commit 7e7ddcb45f
4 changed files with 112 additions and 113 deletions

View File

@ -7,60 +7,51 @@ module.exports = {
run: async (client, interaction) => {
// Declare a random var for the main modal - Each Session
let rand = Math.floor(Math.random() * 99999999999999).toString();
// Declare a random ID for the modal to ensure unique interactions
const modalId = `modal-${Math.floor(Math.random() * 99999999999999).toString()}`;
// Check if this is a chatInput
if (!interaction.isChatInputCommand()) return;
// Check if this is a chatInput command interaction
if (!interaction.isChatInputCommand()) return;
// await interaction.deferReply();
// Create the modal
const modal = new ModalBuilder()
.setCustomId(rand)
.setCustomId(modalId)
.setTitle('This is an example modal');
// TODO: Add components to modal...
// Create a text input component for the modal
const modalInputData = new TextInputBuilder()
.setCustomId('modalInput')
// The label is the prompt the user sees for this input
.setLabel("What text do you want to send?")
// Short means only a single line of text
.setStyle(TextInputStyle.Paragraph);
.setStyle(TextInputStyle.Paragraph); // Allows for multi-line text
// An action row only holds one text input,
// so you need one action row per text input.
const modalInputRow = new ActionRowBuilder().addComponents([modalInputData]);
// Wrap the text input in an action row
const modalInputRow = new ActionRowBuilder().addComponents(modalInputData);
// Add inputs to the modal
modal.addComponents([modalInputRow]);
// Add the input row to the modal
modal.addComponents(modalInputRow);
// Show the modal to the user
await interaction.showModal(modal);
client.on('interactionCreate', interaction => {
// Handle the modal submission within the same interaction listener
client.once('interactionCreate', async (modalInteraction) => {
// Do not continue if its a modal
if (interaction.type == "modal") return
// Interaction type is 5 == Modal
if (interaction.type === 5) {
// Ensure we are handling the correct modal submission
if (!modalInteraction.isModalSubmit() || modalInteraction.customId !== modalId) return;
// Make sure we are working with our users modal only
if (interaction.customId === rand) {
// Retrieve the data entered by the user
const modalInputDataString = modalInteraction.fields.getTextInputValue('modalInput');
// Get the data entered by the user
let modalInputDataString = interaction.fields.getTextInputValue('modalInput');
console.log(modalInputDataString)
const embed = new EmbedBuilder()
// Set color to blue
.setColor("#FF0000")
.setTitle("Your input!")
.setDescription(`You said: ${modalInputDataString}`)
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
interaction.reply({ embeds: [embed] });
}
}
})
// Create an embed to display the user input
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("Your input!")
.setDescription(`You said: ${modalInputDataString}`)
.setTimestamp()
.setFooter({ text: `Requested by ${modalInteraction.user.tag}`, iconURL: modalInteraction.user.displayAvatarURL() });
// Reply to the modal submission with the embed
await modalInteraction.reply({ embeds: [embed] });
});
}
}
};

View File

@ -2,14 +2,14 @@ const { EmbedBuilder } = require('discord.js');
module.exports = {
name: "ping",
private: true,
private: true, // Mark this command as private for ephemeral replies
description: "Returns websocket latency",
run: async (client, interaction) => {
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("🏓 Pong!")
.setDescription(`Latency : ${client.ws.ping}ms`)
.setDescription(`Latency: ${client.ws.ping}ms`)
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
interaction.followUp({ embeds: [embed] });