say.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Permissions } from 'discord.js';
  2. /**
  3. * Processes the "say" command.
  4. * @param {import('../util/i18n.js').default} 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').default} 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. let allowedMentions = {parse:['users']};
  25. if ( msg.member.permissions.has(Permissions.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( {
  28. content: text,
  29. files: imgs,
  30. allowedMentions,
  31. reply: {
  32. messageReference: msg.reference?.messageId
  33. }
  34. } ).then( () => msg.delete().catch(log_error), error => {
  35. log_error(error);
  36. msg.reactEmoji('error', true);
  37. } );
  38. } else if ( !pausedGuilds.has(msg.guildId) ) this.LINK(lang, msg, line, wiki);
  39. }
  40. export default {
  41. name: 'say',
  42. everyone: false,
  43. pause: false,
  44. owner: true,
  45. run: cmd_say
  46. };