From a6449b93e4915dcd6c17354a7127b9796f97d57e Mon Sep 17 00:00:00 2001
From: Supositware <sup@libtar.de>
Date: Thu, 24 Nov 2022 21:30:42 +0100
Subject: [PATCH] Command to dm users

---
 commands/owner/dm.js | 68 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 commands/owner/dm.js

diff --git a/commands/owner/dm.js b/commands/owner/dm.js
new file mode 100644
index 0000000..10c28c8
--- /dev/null
+++ b/commands/owner/dm.js
@@ -0,0 +1,68 @@
+import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
+// const feedbackID = [];
+
+export default {
+	data: new SlashCommandBuilder()
+		.setName('dm')
+		.setDescription('Replies with Pong!')
+		.addStringOption(option =>
+			option.setName('userid')
+				.setDescription('The user to who you want to send the message to.')
+				.setRequired(true))
+		.addStringOption(option =>
+			option.setName('message')
+				.setDescription('What do you want to tell them?')
+				.setRequired(true))
+		.addAttachmentOption(option =>
+			option.setName('image')
+				.setDescription('Optional attachment.')
+				.setRequired(false)),
+	category: 'owner',
+	async execute(interaction, args, client) {
+		/* Too lazy to implement that now (Watch it rest untouched for months)
+		async function uuidv4() {
+			return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
+				const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
+				return v.toString(16);
+			});
+		}
+
+		const uuid = uuidv4();
+		feedbackID[uuid] = args.message;
+		*/
+		await client.users.fetch(args.userid);
+		const user = client.users.resolve(args.userid);
+		if (!user) return interaction.reply('Not a valid ID');
+		const text = args.message;
+
+		const Embed = new EmbedBuilder()
+			.setTitle('You received a message from the developer!')
+			.setDescription(text)
+			.setFooter({ text: `If you wish to respond use the following command: ${interaction.prefix}feedback <message>` })
+			.setTimestamp();
+
+		user.send({ embeds: [Embed] });
+		return interaction.reply({ content: `DM sent to ${user.username}`, ephemeral: true });
+		/*
+		const Attachment = (message.attachments).array();
+		if (Attachment[0]) {
+			client.users.resolve(user).send(Embed, { files: [Attachment[0].url] })
+				.then(() => {
+					return interaction.reply(`DM sent to ${user.username}`);
+				})
+				.catch(() => {
+					return interaction.reply(`Could not send a DM to ${user.username}`);
+				});
+		}
+		else {
+			client.users.resolve(user).send(Embed)
+				.then(() => {
+					return interaction.reply(`DM sent to ${user.tag}`);
+				})
+				.catch(() => {
+					return interaction.reply(`Could not send a DM to ${user.tag}`);
+				});
+		}
+        */
+	},
+};