Advertisement
Nimbi

autopublish.ts

Jul 14th, 2021
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { config } from '../config/cfg';
  2.  
  3. discord.on('MESSAGE_CREATE', async (message) => {
  4.   const errorChannel = await discord.getTextChannel(
  5.       config.modules.errors.channel
  6.     );
  7.     if (!errorChannel) throw new Error('Invalid Channel');
  8.   if (
  9.     !config.modules.automated.autopublisher.enabled &&
  10.     !config.modules.automated.autopublisher.blacklist &&
  11.     !config.modules.automated.autopublisher.announcements
  12.   )
  13.     return;
  14.   try {
  15.     for (
  16.       let i = 0;
  17.       i < config.modules.automated.autopublisher.channels.length;
  18.       i++
  19.     ) {
  20.       let id = config.modules.automated.autopublisher.channels[i];
  21.       let channel = await discord.getGuildNewsChannel(id);
  22.       if (message.channelId !== id || !channel) return;
  23.  
  24.       await channel!.publishMessage(message.id);
  25.     }
  26.   } catch (err) {
  27.     console.error(err);
  28.     errorChannel.sendMessage(
  29.       '```css\n' +
  30.         config.msg.DISCORD_API_ERROR +
  31.         ':' +
  32.         err.code +
  33.         '[' +
  34.         err.message +
  35.         ']\n```'
  36.     );
  37.   }
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement