forked from Markus-Rost/discord-wiki-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsay.js
48 lines (46 loc) · 1.52 KB
/
say.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { PermissionFlagsBits } from 'discord.js';
/**
* Processes the "say" command.
* @param {import('../util/i18n.js').default} lang - The user language.
* @param {import('discord.js').Message} msg - The Discord message.
* @param {String[]} args - The command arguments.
* @param {String} line - The command as plain text.
* @param {import('../util/wiki.js').default} wiki - The wiki for the message.
*/
export default function cmd_say(lang, msg, args, line, wiki) {
var text = args.join(' ');
var imgs = [];
if ( msg.uploadFiles() ) imgs = msg.attachments.map( function(img) {
return {attachment:img.url,name:img.filename};
} );
if ( text.includes( '${' ) ) {
try {
text = eval( '`' + text + '`' );
} catch ( error ) {
log_error(error);
}
}
if ( text.trim() || imgs.length ) {
let allowedMentions = {parse:['users']};
if ( msg.member.permissions.has(PermissionFlagsBits.MentionEveryone) ) allowedMentions.parse = ['users','roles','everyone'];
else allowedMentions.roles = msg.guild.roles.cache.filter( role => role.mentionable ).map( role => role.id ).slice(0, 100);
msg.channel.send( {
content: text,
files: imgs,
allowedMentions,
reply: {
messageReference: msg.reference?.messageId
}
} ).then( () => msg.delete().catch(log_error), error => {
log_error(error);
msg.reactEmoji('error', true);
} );
} else if ( !pausedGuilds.has(msg.guildId) ) this.LINK(lang, msg, line, wiki);
}
export const cmdData = {
name: 'say',
everyone: false,
pause: false,
owner: true,
run: cmd_say
};