diff --git a/src/discord/Say.ts b/src/discord/Say.ts index bc0eefd..4c39e16 100644 --- a/src/discord/Say.ts +++ b/src/discord/Say.ts @@ -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 DiscordProvider from "../providers/Discord"; @@ -10,22 +10,44 @@ export default class Say { if(message.member === null) return; if(message.guild === null) return; - if (!message.member.permissions.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_CHANNELS])) - return await sendReply(message, { + await this.sendSayMessage(false, message, args); + } + + 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 ({ 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) - return await sendReply(message, { + return await sendReply(data, { embeds: [makeErrorEmbed({ 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(" ") }); + } + } } \ No newline at end of file