Add use_modal param to speak command

This commit is contained in:
Daniel 2022-05-22 15:48:30 -07:00
parent af78c3dc60
commit d8f2e77a73
No known key found for this signature in database
GPG Key ID: 771601B78F6934C8
3 changed files with 88 additions and 0 deletions

View File

@ -546,6 +546,12 @@ const utilityCommands: ApplicationCommandOptionData[] = [
description: "Whether or not to have pings (allowed_mentions)",
required: false,
},
{
type: "BOOLEAN",
name: "use_modal",
description: "Use Modal to send text instead of provided text param",
required: false,
},
],
},
];

View File

@ -9,6 +9,49 @@ export default new Command({
let text = interaction.options.getString("text");
let disable_ping: boolean =
interaction.options.getBoolean("disable_ping", false) || false;
let use_modal: boolean =
interaction.options.getBoolean("use_modal", false) || false;
if (use_modal)
return (
// @ts-expect-error
interaction.client.api
// @ts-expect-error
.interactions(interaction.id)(interaction.token)
.callback.post({
data: {
type: 9,
data: {
components: [
{
type: 1,
components: [
{
type: 4,
custom_id: "text",
style: 2,
label: "Text",
},
],
},
{
type: 1,
components: [
{
type: 4,
custom_id: "mentions_disabled",
style: 2,
label: "Disable mentions? true/false",
},
],
},
],
title: "Speak: Large Input",
custom_id: "speak_large_input",
},
},
})
);
let responseMessage: MessageOptions = {
content: text,

View File

@ -0,0 +1,39 @@
import { MessageOptions, ThreadChannel } from "discord.js";
import { config } from "../../config";
import ModalCommand from "../classes/ModalCommand";
export default new ModalCommand({
customId: "speak_large_input",
staffOnly: true,
async execute(interaction, client) {
let messageText =
interaction.data.components[0]?.components[0]?.value || "";
let disable_ping = Boolean(
interaction.data.components[1]?.components[0]?.value || false
);
// @ts-expect-error
client.api
//@ts-expect-error
.interactions(interaction.id)(interaction.token)
.callback.post({
data: {
type: 4,
data: {
content: `Sent!`,
flags: 64,
},
},
});
let channel = client.channels.cache.get(interaction.channel_id);
if (channel.isText()) {
let responseMessage: MessageOptions = {
content: messageText,
};
if (disable_ping)
responseMessage.allowedMentions = {
parse: [],
};
channel.send(responseMessage);
}
},
});