From 41b59f8b927edda812f58470895c9ca5fcf9d79e Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Tue, 16 May 2023 14:06:51 -0400 Subject: [PATCH] Add basic message command --- dot-commands/message.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 dot-commands/message.js diff --git a/dot-commands/message.js b/dot-commands/message.js new file mode 100644 index 0000000..d0efcaf --- /dev/null +++ b/dot-commands/message.js @@ -0,0 +1,39 @@ +const fn = require('../modules/functions.js'); + +module.exports = { + name: "message", + description: "Send a message to a server owner or server", + usage: ".message ", + async execute(message, commandData) { + if (message.client.guildInfos.has(commandData.args[0])) { + let guildInfo = message.client.guildInfos.get(commandData.args[0]); + const guild = await message.client.guilds.fetch(commandData.args[0]).catch(async e => { + await message.reply("I was unable to fetch the guild."); + console.error(`Error fetching guild to send message: ${e}`); + }); + const guildOwner = await message.client.users.fetch(guild.ownerId).catch(async e => { + await message.reply("I was unable to fetch the guild owner."); + console.error(`Error fetching guild owner to send message: ${e}`); + }); + await guildOwner.createDM().then(async dm => { + await dm.send(commandData.args.join(" ")).catch(async e => { + await message.reply("I was unable to send the DM."); + console.error(`Error sending DM message: ${e}`); + }); + }).catch(async e => { + await message.reply("I was unable to create the DM."); + console.error(`Error creating DM to send message: ${e}`); + const channel = await guild.channels.fetch(guildInfo.reminderChannelId).catch(async e => { + await message.reply("I was unable to fetch the channel."); + console.error(`Error fetching channel to send message: ${e}`); + }); + await channel.send(commandData.args.join(" ")).catch(async e => { + await message.reply("I was unable to send the message."); + console.error(`Error sending message: ${e}`); + }); + }); + } else { + throw "Guild doesn't exist in database!"; + } + } +} \ No newline at end of file