Support Interaction

This commit is contained in:
2021-09-17 05:21:01 -07:00
parent 1f48f6ad85
commit cdecb86d43
+29 -7
View File
@@ -1,4 +1,4 @@
import { Message, Permissions } from "discord.js"; import { Message, Permissions, CommandInteraction } from "discord.js";
import { getEmotes, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendReply, makeErrorEmbed } from "../utils/DiscordMessage"; import { getEmotes, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendReply, makeErrorEmbed } from "../utils/DiscordMessage";
import DiscordProvider from "../providers/Discord"; import DiscordProvider from "../providers/Discord";
@@ -10,22 +10,44 @@ export default class Say {
if(message.member === null) return; if(message.member === null) return;
if(message.guild === null) return; if(message.guild === null) return;
if (!message.member.permissions.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_CHANNELS])) await this.sendSayMessage(false, message, args);
return await sendReply(message, { }
async interactionCreate(interaction: CommandInteraction) {
if(typeof interaction.commandName === 'undefined') return;
if((interaction.commandName).toLowerCase() !== 'say') return;
await this.sendSayMessage(true, interaction, interaction.options.getString('message'));
}
async sendSayMessage(isSlashCommand: boolean, data: any, args: any) {
if (!data.member.permissions.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_CHANNELS]))
return await sendReply(data, {
embeds: [makeErrorEmbed ({ embeds: [makeErrorEmbed ({
title: 'You need ``VIEW_CHANNEL, SEND_MESSAGES and MANAGE_CHANNELS`` permission on this guild!', title: 'You need ``VIEW_CHANNEL, SEND_MESSAGES and MANAGE_CHANNELS`` permission on this guild!',
user: message.author user: isSlashCommand ? data.user : data.author
})] })]
}); });
if(args.length === 0) if(args.length === 0)
return await sendReply(message, { return await sendReply(data, {
embeds: [makeErrorEmbed({ embeds: [makeErrorEmbed({
title: `No message defined`, title: `No message defined`,
user: message.author user: isSlashCommand ? data.user : data.author
})] })]
}); });
await message.channel.send({ content: args.join(" ") }); if(isSlashCommand) {
await data.channel.send({ content: args });
await data.reply({ ephemeral: true, embeds: [makeSuccessEmbed({
title: `Successfully said`,
user: isSlashCommand ? data.user : data.author
})] });
}
else {
await data.channel.send({ content: args.join(" ") });
}
} }
} }