/[sudobot]/trunk/commands/send.js
ViewVC logotype

Annotation of /trunk/commands/send.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (hide annotations)
Mon Jul 29 17:28:16 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 2165 byte(s)
Added -send command and added support of attachments in snippets
1 rakin 27 const { emoji } = require('../src/emoji');
2     const MessageEmbed = require('../src/MessageEmbed');
3    
4     module.exports = {
5     async handle(msg, cm) {
6     if (cm.args[0] === undefined) {
7     await msg.reply({
8     embeds: [
9     new MessageEmbed()
10     .setColor('#f14a60')
11     .setDescription('This command requires at least 2 arguments')
12     ]
13     });
14    
15     return;
16     }
17    
18     let user = msg.mentions.members.first();
19    
20     if (!user) {
21     user = msg.guild.members.cache.find(m => m.id === cm.args[0]);
22     }
23    
24     if (!user) {
25     await msg.reply({
26     embeds: [
27     new MessageEmbed()
28     .setColor('#f14a60')
29     .setDescription('Invalid user given.')
30     ]
31     });
32    
33     return;
34     }
35    
36     const args = [...cm.args];
37     args.shift();
38    
39     if (msg.attachments.size < 1 && args.length < 1) {
40     await msg.reply({
41     embeds: [
42     new MessageEmbed()
43     .setColor('#f14a60')
44     .setDescription('This command requires at least 2 arguments')
45     ]
46     });
47    
48     return;
49     }
50    
51     const content = args.join(' ');
52    
53     try {
54     let message = {};
55    
56     if (content.trim() != '') {
57     message.content = content;
58     }
59    
60     if (msg.attachments && msg.attachments.size > 0) {
61     message.files = msg.attachments.map(a => {
62     return {
63     attachment: a.proxyURL,
64     name: a.name
65     }
66     });
67     }
68    
69     await user.send(message);
70    
71     await msg.reply({
72     content: (await emoji('check'))?.toString() + " Message Sent!"
73     });
74     }
75     catch(e) {
76     console.log(e);
77    
78     await msg.reply({
79     content: "Message could not be sent, maybe the user has disabled DMs?"
80     });
81     }
82     }
83     };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26