Advertisement
Hakuhun

Discord image reposter

Jul 10th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Extract the required classes from the discord.js module
  2. const { Client, MessageAttachment } = require('discord.js');
  3.  
  4. // Create an instance of a Discord client
  5. const client = new Client();
  6.  
  7. /**
  8.  * The ready event is vital, it means that only _after_ this will your bot start reacting to information
  9.  * received from Discord
  10.  */
  11. client.on('ready', () => {
  12.   console.log('I am ready!');
  13. });
  14.  
  15. client.on('message', message => {
  16.     //if bot sends something
  17.     if(message.author.bot) return;
  18.     // If the message contains attachments
  19.     if (message.attachments &&  message.attachments.length > 0) {
  20.         //iterate trough attachments
  21.         message.attachments.forEach(element => {
  22.             // Send the attachment in the message channel with a content
  23.             message.channel.send(`${message.author},`, element);            
  24.         });
  25.     }
  26. });
  27.  
  28. client.login('your token here');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement