say.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const {Permissions: {FLAGS}} = require('discord.js');
  2. /**
  3. * Processes the "say" command.
  4. * @param {import('../util/i18n.js')} lang - The user language.
  5. * @param {import('discord.js').Message} msg - The Discord message.
  6. * @param {String[]} args - The command arguments.
  7. * @param {String} line - The command as plain text.
  8. * @param {import('../util/wiki.js')} wiki - The wiki for the message.
  9. */
  10. function cmd_say(lang, msg, args, line, wiki) {
  11. var text = args.join(' ');
  12. var imgs = [];
  13. if ( msg.uploadFiles() ) imgs = msg.attachments.map( function(img) {
  14. return {attachment:img.url,name:img.filename};
  15. } );
  16. if ( text.includes( '${' ) ) {
  17. try {
  18. text = eval( '`' + text + '`' );
  19. } catch ( error ) {
  20. log_error(error);
  21. }
  22. }
  23. if ( text.trim() || imgs.length ) {
  24. var allowedMentions = {parse:['users']};
  25. if ( msg.member.permissions.has(FLAGS.MENTION_EVERYONE) ) allowedMentions.parse = ['users','roles','everyone'];
  26. else allowedMentions.roles = msg.guild.roles.cache.filter( role => role.mentionable ).map( role => role.id ).slice(0,100)
  27. msg.channel.send( {content: text, allowedMentions, files: imgs} ).then( () => msg.delete().catch(log_error), error => {
  28. log_error(error);
  29. msg.reactEmoji('error', true);
  30. } );
  31. } else if ( !pause[msg.guildId] ) this.LINK(lang, msg, line, wiki);
  32. }
  33. module.exports = {
  34. name: 'say',
  35. everyone: false,
  36. pause: false,
  37. owner: true,
  38. run: cmd_say
  39. };