import { Command } from 'discord-akairo'; import { Message } from 'discord.js'; import { colour } from '../../Config'; export default class DMOwner extends Command { public constructor() { super('dm', { aliases: ['dm', 'pm'], category: 'owner', description: { content: 'DM a specified user.', usage: '[user id] [message]', examples: [ '217348698294714370 hi' ] }, ratelimit: 3, args: [ { id: 'user', type: 'string' }, { id: 'type', type: 'string', prompt: { start: 'What type of DM would you like to send the specified user?', retry: 'That is not a valid DM type!' } }, { id: 'text', type: 'string', prompt: { start: 'What would you like to send to the specified user?' }, match: 'rest' } ], ownerOnly: true }); } public exec(msg: Message, { user, type, text }): Promise { if (type == 'embed') { function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { let r = Math.random() * 16 | 0, v = c == 'x' ? r : (4 & 0x3 | 0x8); return v.toString(16); }); } const uuid = uuidv4(); user = this.client.users.resolve(user); if (!user) return msg.channel.send('An incorrect user ID was provided.'); const embed = this.client.util.embed() .setTitle('You received a message from the developer!') .setColor(colour) .setDescription(text) .setFooter(`If you wish to respond, use the following command: ${this.client.commandHandler.prefix}feedback --reply ${uuid} `) .setTimestamp(); let attachment = (msg.attachments).array(); if (attachment[0]) { this.client.users.resolve(user).send(embed, { files: [attachment[0].url] }) .then(() => { return msg.channel.send(`A DM has successfully been sent to ${user.username}.`)}) .catch(() => { return msg.channel.send(`Could not send a DM to ${user.username}.`)}); } else { this.client.users.resolve(user).send(embed) .then(() => { return msg.channel.send(`A DM has successfully been sent to ${user.tag}.`)}) .catch(() => { return msg.channel.send(`Could not send a DM to ${user.tag}.`)}); } } else if (type === 'normal') { let attachment = (msg.attachments).array(); if (attachment[0]) { this.client.users.resolve(user).send(text, { files: [attachment[0].url] }) .then(() => { return msg.channel.send(`A DM has successfully been sent to ${user.username}.`)}) .catch(() => { return msg.channel.send(`Could not send a DM to ${user.username}.`)}); } else { this.client.users.resolve(user).send(text) .then(() => { return msg.channel.send(`A DM has successfully been sent to ${user.tag}.`)}) .catch(() => { return msg.channel.send(`Could not send a DM to ${user.tag}.`)}); } } return; } }